2013-08-22 98 views
0

我們正在爲我們的WPF應用程序使用「serialized xml」文件。 我們使用下面的代碼來保存相應的Class對象。將自定義文件屬性添加到文件

public static bool SerializeToXml<T>(T configType, string filePath) 
     { 
      bool status = false; 
       XmlWriterSettings xmlWriterSettings; 
       XmlSerializerNamespaces xmlSerializerNamespaces; 

       xmlWriterSettings = new XmlWriterSettings 
       { 
        Indent = true, 
        OmitXmlDeclaration = false, 
        NamespaceHandling = NamespaceHandling.OmitDuplicates, 
        Encoding = Encoding.UTF8, 

       }; 
       xmlSerializerNamespaces = new XmlSerializerNamespaces(); 
       xmlSerializerNamespaces.Add("", ""); 

       if (!Directory.Exists(Path.GetDirectoryName(filePath))) 
        Directory.CreateDirectory(Path.GetDirectoryName(filePath)); 

       using (FileStream configurationFileStream = new FileStream(filePath, FileMode.Create)) 
       { 

        using (XmlWriter xmlWriter = XmlWriter.Create(configurationFileStream, xmlWriterSettings)) 
        { 
         XmlSerializer serializer = new XmlSerializer(typeof(T)); 
         serializer.Serialize(xmlWriter, configType, xmlSerializerNamespaces); 
        } 
       } 

       status = true; 

      return status; 
     } 

截至目前,我們需要保持版本號爲「文件屬性」中的一個。(所以一旦用戶右鍵單擊該文件,然後單擊「詳細信息」,用戶可以看到版本號) 我們如何實現這一目標?

回答

相關問題