2013-02-21 125 views
1

我有一個在開發環境中工作的函數,但我需要更改路徑,以便在主機服務器上正確解析。在函數中解析文件路徑

此代碼行;

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")更換字符串作爲服務器不工作中

不在該範圍內都有效。任何想法如何解決這個路徑

回答

2

服務器總是可以達到這樣的:

string filePath = System.Web.HttpContext.Current.Server.MapPath("~/OtherDataFiles/dataXML.xml"); 
doc.Load(filePath); 

如果一個類庫項目裏面你可以添加引用System.Web程序集。