2011-11-03 133 views
0

我有一個xml文件,聲明爲samplexml.xml,我將它存儲在名爲SampleFolder的文件夾中。這裏的層次結構如何:在解決方案中查找文件

Solution-> Project-> SampleFolder-> samplexml.xml。假設我位於項目中名爲TestClass.cs的類中,如何讀取字符串中xml文件的所有內容。

比方說,

[TestClass] 
public class TestClass 
{ 
    [TestMethod] 
    public void TestMethod() 
    { 
     //TODO: Read all the contents of the xml file in a string. 
    } 

} 

如何做到這一點?

+0

胡言亂語! – Arun

+0

使用XMLReader ...因爲你甚至沒有嘗試過使用它,這可能是一個練習,回到實際的問題。 –

回答

0

嘗試:

string exePath = Path.GetDirectory(Assembly.GetExecutingAssembly().Location); 
string xmlPath = Path.Combine(exePath, "SampleFolder"); 
string fileName = Path.Combine(xmlPath, "SampleXML.xml"); 

記住,你應該設置編譯器的XML文件複製到目標目錄

+0

謝謝,這對我有用。 – DotNetUser

相關問題