2012-05-30 32 views
1

我有一個XML文件,我想將其作爲嵌入式資源與我的應用程序一起包含,以便該文件使用.exe編譯並且對用戶不可用。我可以訪問嵌入資源並將其保存爲文件嗎?

眼下,該文件位於

[approot]/ConfigurationFiles/Defaults/Core.xml 

我希望能夠從這個嵌入的資源創建一個XDocument,然後是保存到磁盤,以便用戶可以訪問它。

我該怎麼做?我如何訪問嵌入式資源並從中創建XDocument?

回答

0

你只打開一個流,讀取資源,你想要什麼用它做什麼:

<Assembly default namespace>.<path to the resource>.<resource name> 

using (Stream stream = assembly.GetManifestResourceStream(".../ConfigurationFiles/Defaults/Core.xml")); 
{ 
    // turn it to a XDocument and store it 
    XDocument doc = XDocument.Load(stream); 
    // ... 
} 

的路徑名稱資源是由組成

相關問題