Asp.net 解析函数中的文件路径
我有一个在开发环境中工作的函数,但我需要更改路径,以便它在主机服务器上正确解析 这个代码行Asp.net 解析函数中的文件路径,asp.net,Asp.net,我有一个在开发环境中工作的函数,但我需要更改路径,以便它在主机服务器上正确解析 这个代码行 doc.Load("H:\Website_Sep2012\OtherDataFiles\dataXML.xml") 'this needs to be changed to the server path 在这一职能范围内 Public Shared Function GetList(ByVal nodestring As String) As List(Of String) Dim doc A
doc.Load("H:\Website_Sep2012\OtherDataFiles\dataXML.xml") 'this needs to be changed to the server path
在这一职能范围内
Public Shared Function GetList(ByVal nodestring As String) As List(Of String)
Dim doc As New XmlDocument()
'Load XML from the file into XmlDocument object
doc.Load("H:\Website_Sep2012\OtherDataFiles\dataXML.xml") 'this needs to be changed to the server path
Dim root As XmlNode = doc.DocumentElement
'Select all nodes with the tag paramter indicated by the nodestring variable
Dim nodeList As XmlNodeList = root.SelectNodes(nodestring)
Return (From node As XmlNode In nodeList Select node.InnerText).ToList()
End Function
将字符串替换为
Server.MapPath(“~/OtherDataFiles\dataXML.xml”)
不起作用,因为服务器在该范围内不可用。任何解决此路径的方法都可以通过以下方式到达服务器:
string filePath = System.Web.HttpContext.Current.Server.MapPath("~/OtherDataFiles/dataXML.xml");
doc.Load(filePath);
如果在类库项目中,您只需添加对System.Web assembly的引用。始终可以像这样访问服务器:
string filePath = System.Web.HttpContext.Current.Server.MapPath("~/OtherDataFiles/dataXML.xml");
doc.Load(filePath);
如果在类库项目中,您只需添加对System.Web assembly的引用。您还可以尝试:
不需要HttpContext
或
您也可以尝试:
不需要HttpContext
或