LoadFromFile using a mapped network drive

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cryogeneric
    New Member
    • Jan 2008
    • 15

    LoadFromFile using a mapped network drive

    Hello everyone

    I'm creating an ASP classic application that let's users download and save PDF files without having to bring them up in the browser. I have successfully used the LoadFromFile method to perform this feat but not in the manner in which I ultimately want things to be.

    Currently the PDF's sit on the server itself, but I would like for these to be on a different computer. When I try to set up this scenario, the LoadFromFile method can never find the file.

    My first thought was to Map a network drive to the location of the PDF's on the other computer. Still, LoadFromFile can't find the files.

    Is there any way to use LoadFromFile on the server, but have the file I'm looking for reside on a diffrent computer on the same network?
    Here is my logic....

    Where I set the CompletePath variable, "S:" is the mapped network drive.

    Code:
    If Len(Trim(Session("MEMBER_ID"))) > 0 Then
    	Response.Clear
    	Response.contentType = "application/octet-stream"
    	Response.addheader "content-disposition", "attachment; filename=" & FileName
    
    	Set Stream = server.CreateObject("ADODB.Stream")
    
    	Stream.Type = adTypeBinary
    	Stream.Open
    
    	CompletePath = "S:\Inetpub\wwwroot\PDF\" & GroupName & "\" & FileName
    
    	Stream.LoadFromFile CompletePath 
    	While Not Stream.EOS
    		Response.BinaryWrite Stream.Read(1024 * 64)
    	Wend
    
    	Stream.Close
    	Set Stream = Nothing
    
    	'Response.write("<html>")
    	'Response.write(CompletePath)
    	'Response.write("</html>")
    
    	Response.Flush
    	Response.End
    End If
    Thanks a million!!!!!! Any help would be wonderful. :)
  • danp129
    Recognized Expert Contributor
    • Jul 2006
    • 323

    #2
    Try loading the full UNC path "\\servername\s harename\subfol der\filename.ex t" and make sure the file has read rights given to the "IUSR_wwwserver " user account.

    Comment

    • cryogeneric
      New Member
      • Jan 2008
      • 15

      #3
      Hi danp129, Thanks so much for the response.

      The web server will vpn to a computer behind the firewall that contains the files. So by "servername ", I'm assuming IP address will be fine.

      In other words: \\100.100.100.1 \pdf\somefile.p df

      Theoretically, I don't see any reason why this shouldn't work. The path shouldn't matter if the server can read from the folder (which it can). But it doesn't work. :(

      The PDF folder is currently shared, AND I turned on "web sharing".

      Comment

      • cryogeneric
        New Member
        • Jan 2008
        • 15

        #4
        Solved!

        While for whatever reason I'm unable to run LoadFromFile and read from a folder on a different computer, I was able to solve the problem by placing the script that calls the LoadFromFile method on the Network computer and calling THE SCRIPT using the IP address.

        I guess LoadFromFile is unable to read from a folder that is not physically on the computer that the script is called from. Seems weird, but trust me, I spent hours trying to get it to work.

        Comment

        • DrBunchman
          Recognized Expert Contributor
          • Jan 2008
          • 979

          #5
          That's interesting. The FileSystem object has a similar drawback where the Exists property always returns false if you use it on a file stored on a different machine. This is a good solution though to call a script running on the remote server.

          Glad you got it sorted.

          Dr B

          Comment

          • cryogeneric
            New Member
            • Jan 2008
            • 15

            #6
            Thanks.

            That's good to know about the FileExists method. I suspect this solution could be used to get around that problem as well. Of course, IIS needs to be setup on the remote server.

            In fact, now that I think about... I wonder if you could "include" a script on the remote server which has subs that call FileExists or LoadFromFile... hmmm

            I might have to test that someday. :)

            Comment

            • danp129
              Recognized Expert Contributor
              • Jul 2006
              • 323

              #7
              I think the problem with mapped drives is that mapped drives are user specific and IUSR_ doesn't have any mapped drives.

              Comment

              Working...