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"
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"