Click to See Complete Forum and Search --> : FileInfo Class Path Problem


kwilliams
04-17-2007, 05:50 PM
FileInfo Class Path Problem

My problem is that my application properly pulls an ASP.NET file on my machine using Visual Web Developer 2005, but it doesn't pull it properly when a copy of the application was uploaded to our test server. On my machine, I listed the entire path for the ASP.NET doc to be pulled (c:\Documents and Settings\MYUSERNAME\My Documents\Visual Studio 2005\Projects\DIRECTORY\SUBDIRECTORY\PAGE.aspx). On the test server, I'm attempting to pull the ASP.NET doc with a UNC share (\\SERVERNAME\DIRECTORY\SUBDIRECTORY\PAGE.aspx).

I'm using the FileInfo Class to do this, and I've included the two versions of code below. If anyone could please let me know what I'm doing wrong, that would be great. (Hopefully it's something obvious) Thanks.

OLD METHOD ON MACHINE:

Partial Class MasterPage
Inherits System.Web.UI.MasterPage
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

'Assign page path to string value
Dim strPagePath = Request.ServerVariables("PATH_INFO")
Response.Write("<strong>strPagePath: </strong>" & strPagePath & "<br />") 'test

'Assign full page path
Dim strFullPagePath = "c:\Documents and Settings\MYUSERNAME\My Documents\Visual Studio 2005\Projects" & strPagePath

'Assign path to FileInfo Class
Dim fi As FileInfo = New FileInfo(strFullPagePath)
Dim strPageId As String, strPathNoFileName As String
Dim strXMLPath_mc As String, strXSLPath_mc As String, strCSSPath As String

'Check if files exist
If Not fi.Exists Then
strPageId = "default"
strPathNoFileName = "http://localhost:1309/DIRECTORYNAME"
Else
strPageId = fi.Name.Replace(fi.Extension, "") 'without extension
strPathNoFileName = strPagePath.Replace(fi.Name, "")
'Assign dynamic page paths
strXMLPath_mc = strPathNoFileName + "docs/xml/" & strPageId & ".xml" 'xml doc
strXSLPath_mc = strPathNoFileName + "docs/xslt/" & strPageId & ".xsl" 'xsl doc
strCSSPath = strPathNoFileName + "docs/css/" & strPageId & ".css" 'css doc
End If
End Sub
End Class

RESULTING VALUE:
strFullPagePath = "c:\Documents and Settings\MYUSERNAME\My Documents\Visual Studio 2005\Projects\DIRECTORY\SUBDIRECTORY\PAGE.aspx"


NEW METHOD ON TEST SERVER:

Partial Class MasterPage
Inherits System.Web.UI.MasterPage
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

'Assign page path to string value
Dim strPagePath = Request.ServerVariables("PATH_INFO")
Dim strPagePath_fi As String = strPagePath.Replace("/", "\") 'replace slash
Dim strFullPagePath = "\\SERVERNAME\DIRECTORY" & strPagePath_fi '<---THIS IS THE PROBLEM

'Assign path to FileInfo Class
Dim fi As FileInfo = New FileInfo(strFullPagePath)
Dim strPageId As String, strPathNoFileName As String
Dim strXMLPath_mc As String, strXSLPath_mc As String, strCSSPath As String

'Check if files exist
If Not fi.Exists Then
strPageId = "default"
strPathNoFileName = "http://SERVERNAME/DIRECTORY"
Else
strPageId = fi.Name.Replace(fi.Extension, "") 'without extension
strPathNoFileName = strPagePath.Replace(fi.Name, "")
'Assign dynamic page paths
strXMLPath_mc = strPathNoFileName + "docs/xml/" & strPageId & ".xml" 'xml doc
strXSLPath_mc = strPathNoFileName + "docs/xslt/" & strPageId & ".xsl" 'xsl doc
strCSSPath = strPathNoFileName + "docs/css/" & strPageId & ".css" 'css doc
End If
End Sub
End Class

RESULTING VALUE:
strFullPagePath = "\\SERVERNAME\DIRECTORY\SUBDIRECTORY\PAGE.aspx"

PeOfEo
04-17-2007, 06:07 PM
Hrm, that's an interesting one. Is mapping the remote machine as a network drive an option? If so that would make things much easier.

kwilliams
04-18-2007, 09:37 AM
Hrm, that's an interesting one. Is mapping the remote machine as a network drive an option? If so that would make things much easier.

Thanks for the quick response PeOfEo. I did actually already try that by mapping that server to my z drive and referencing the drive like this,:

Dim strFullPagePath = "z:" & strPagePath

...which resulted in this: z:\DIRECTORY\SUBDIRECTORY\PAGE.aspx

...but it still didn't work. If you or anyone else has any other suggestions, that would be great. Thanks.

Ribeyed
04-19-2007, 03:56 PM
Hi,
I store my application path in the registry then pull the path from the registry in my global.asa and set it to an application variable which i then use in my code. When testing my registry has my applications local path my live sever has my live's application local path. This way i don't have to change my code.