|
Question : Using Server.Mappath to get a file from a virtual directory
|
|
Hi, and thanks in advance for any and all help with this.
.... the virtual directory is actually a share from another server. It is warehousing a bunch of files that are created and referenced from a completely different application, so it would be VERY impractical to move them to an actual directory.
The share from the other server IS set to allow the EVERYONE account full access to the files.
When I look in the virtual directory using IIS admin, I can see all the files just fine. Here is my code, and what's happening:
Imports System.IO Public Class viewPOD Inherits System.Web.UI.Page Dim strDocID As String Dim intDocID As Decimal Dim intPath As Decimal Dim strPath As String Dim strPathTemp As String Dim x As Integer
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here strDocID = Request.QueryString("docid") intDocID = CInt(strDocID) intPath = intDocID / 1024 strPath = CStr(intPath) strPath = Trim(strPath) x = strPath.IndexOf(".") strPathTemp = Left(strPath, x)
Dim thePath As String thePath = Server.MapPath("myfiles/" & strPathTemp & "/" & strDocID & ".bin") File.Copy(thePath, "temp/" & strDocID & ".tiff")
Dim myFile As String myFile = Server.MapPath("temp/" & strDocID & ".tiff") Dim theDoc As Doc = New Doc theDoc.AddImageData(myFile, 1)
Dim theData() As Byte = theDoc.GetData() Response.ContentType = "application/pdf" Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF") Response.AddHeader("content-length", theData.Length.ToString()) Response.BinaryWrite(theData) End Sub
End Class
And here's what happens when I try to view the page:
Could not find file "\\raidserv03\Raider Trucking\POD_SCANS\0\48\49689.bin". Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not find file "\\raidserv03\Raider Trucking\POD_SCANS\0\48\49689.bin".
Source Error:
Line 48: Line 49: thePath = Server.MapPath("myfiles/" & strPathTemp & "/" & strDocID & ".bin") Line 50: File.Copy(thePath, "temp/" & strDocID & ".tiff")
But this is a legitimate filename & path. So what am I doing wrong? Is it the space in the directory name? Is it a permissions thing? This is my development webserver, but when I deploy this, the deployment webserver is also a different one than where these documents are warehoused. So, I need to know how to make this work, so I can duplicate it on my deployment server as well.
for clarification, the myfiles virtual directory does point to "\\raidserv03\Raider Trucking\POD_SCANS\0"
Please help!!
Thanks again in advance! Steve
P.S. Sorry for being so long....
|
|
Answer : Using Server.Mappath to get a file from a virtual directory
|
|
Write this right after a thePath = Server.MapPath....:
Response.Write(thePath & " ") Response.Write("\\raidserv03\Raider Trucking\POD_SCANS\0\" & strPathTemp & "\" & strDocID & ".bin")
See if you get two same lines.
R
|
|
|
|