Using ASP to open excel file

J

jnb0012

Can anyone help with this? Here is the code I am using. The problem
is, where it checks if a file exists, it always goes to else. Even if
the file is there, it won't open the file, goes straight to else part
of statement.

<%
If Session("strLogID") = "" Then
Response.Redirect("http://website/pages/login.asp")

Else
strfile = Request.Form("month") & Request.Form("day") & " Misses" &
".xls"

Set fs = Server.CreateObject("Scripting.FileSystemObject")
If fs.FileExists("http://website/webreports/Misses/" & strfile) THEN

Response.Redirect("http://website/webreports/Misses/" & strfile)

Else
Response.Redirect("http://website/pages/missedreport.asp")

End If
End If
%>
 
B

Bob Barrows [MVP]

Can anyone help with this? Here is the code I am using. The problem
is, where it checks if a file exists, it always goes to else. Even if
the file is there, it won't open the file, goes straight to else part
of statement.


Set fs = Server.CreateObject("Scripting.FileSystemObject")
If fs.FileExists("http://website/webreports/Misses/" & strfile) THEN

A FileSystemObject requires a filesystem path, not a url. Use
Server.MapPath to generate the filesystme path:

url="http://website/webreports/Misses/"
strPathAndFile = Server.MapPath(url & strfile)
'for debugging:
Response.Write "strPathAndFile contains '" & strPathAndFile & _
"'<BR>"
 
M

Mike Brind

Can anyone help with this? Here is the code I am using. The problem
is, where it checks if a file exists, it always goes to else. Even if
the file is there, it won't open the file, goes straight to else part
of statement.

<%
If Session("strLogID") = "" Then
Response.Redirect("http://website/pages/login.asp")

Else
strfile = Request.Form("month") & Request.Form("day") & " Misses" &
".xls"

Set fs = Server.CreateObject("Scripting.FileSystemObject")
If fs.FileExists("http://website/webreports/Misses/" & strfile) THEN

Get rid of http:// and use server.mappath to locate the physical path
of the files
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top