2011-10-11 27 views
3

我有一個Windows窗體C#應用程序。 我想添加一個xml文件到這個.exe 這個xml文件必須是.exe文件的一部分。 我該怎麼做,如何才能訪問程序中的xml文件。如何將xml文件作爲資源添加到Windows Forms exe中

我曾嘗試是這樣的:

Stream st = Assembly.GetExecutingAssembly().GetManifestResourceStream("CApp.xmlfile.xml"); 
StreamReader reader = new StreamReader(st); 

doc = XElement.Load(reader); 

建立xml文件操作是「嵌入的資源」

+0

見http://www.cs.nyu.edu/~vs667/articles/embed_executable_tutorial/加載 –

回答

4

在您要添加它,去到資源項目的屬性 - >添加資源(向下箭頭)添加現有文件。

然後命名它,但是你想要的。

然後你會看到它在你的項目的解決方案 - >屬性(文件夾)Resources.Designer.cs文件。加載它,比如說你命名了資源(文件)CAppxmlfile。

您與XElement resource = XElement.Parse(Properties.Resources.CAppxmlfile);

相關問題