Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 解析函数中的文件路径_Asp.net - Fatal编程技术网

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