2012-05-30 42 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); 
    // ... 
} 

的路径名称资源是由组成

相关问题