System.IO.File.SetAttributes
System.IO.FileAttributes.ReadOnly 

解决方案 »

  1.   

    string fileName = "c:\\aa.txt";
    System.IO.File.SetAttributes(fileName, System.IO.FileAttributes.Normal);  //更新文件的属性为一般属性,即可写。
      

  2.   

    string fileName = "c:\\aa.xml";
    System.IO.File.SetAttributes(fileName, System.IO.FileAttributes.Normal);  //更新文件的属性为一般属性,即可写。
      

  3.   

    string fileName = "D:\test.xml"
    XmlDocument xml = new XmlDocument();
    xml.Load(fileName);
    XmlNodeList tagList = xml.SelectNodes("/testInfo/" + "add[@key='" + key + "']");
    tagList.Item(0).SelectSingleNode("@name").Value ="aaaa";System.IO.File.SetAttributes(fileName, System.IO.FileAttributes.Normal);
    XmlTextWriter writer = new XmlTextWriter(fileName,null);
    xml.Save(writer);
    System.IO.File.SetAttributes(fileName, System.IO.FileAttributes.ReadOnly);
    不知道是不是符合你的要求