Using ASP to open excel file

Discussion in 'ASP General' started by jnb0012@unt.edu, May 31, 2006.

  1. Guest

    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
    %>
     
    , May 31, 2006
    #1
    1. Advertising

  2. wrote:
    > 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>"
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], May 31, 2006
    #2
    1. Advertising

  3. Mike Brind Guest

    wrote:
    > 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

    --
    Mike Brind
     
    Mike Brind, May 31, 2006
    #3
  4. Guest

    I'm working now. Thank you both
     
    , May 31, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,416
    Carl Prothman [MVP]
    Jan 12, 2005
  2. pps!
    Replies:
    0
    Views:
    1,050
  3. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,572
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
  4. viza
    Replies:
    0
    Views:
    675
  5. eddie wang
    Replies:
    0
    Views:
    425
    eddie wang
    Oct 3, 2003
Loading...

Share This Page