2013-05-11 52 views
2

我正在使用C#來追加這樣的xml資源文件。如何在更新後保存xml資源文件?

XmlDocument xmlDoc = new XmlDocument(); 
xmlDoc.LoadXml(Properties.Resources.setup_info); 
XmlNode node = xmlDoc.SelectSingleNode("data/Ename"); 
node.Attributes[1].Value = "true"; 

之後我需要保存資源文件。但是

xmlDoc.Save(path);//needs the file path 

如果我給「Properties.Resources.setup_info」拋出錯誤。

回答

0

您可以使用ResourceWriter此任務

下面是從MSDN

using System; 
using System.Resources; 


public class WriteResources { 
    public static void Main(string[] args) { 

     // Creates a resource writer. 
     IResourceWriter writer = new ResourceWriter("myResources.resources"); 

     // Adds resources to the resource writer. 
     writer.AddResource("String 1", "First String"); 

     writer.AddResource("String 2", "Second String"); 

     writer.AddResource("String 3", "Third String"); 

     // Writes the resources to the file or stream, and closes it. 
     writer.Close(); 
    } 
} 
下面

的示例代碼將XML寫入資源文件ProjXML.resources

using (ResourceWriter rw = new ResourceWriter(@".\ProjXML.resources")) 
    { 
    rw.AddResource("MyXML", xmlDoc.OuterXml); 
    }