How to overwrite files in doc libs? RRS feed

  • Question

  • Hi,

    I'm building a webpart in which you can adjust the steps you undertake in a project.
    These steps are saved in an xml-file. Whenever you change something, it's changed in the xml file aswel.
    So I use an XmlTextReader to read the file, nothing fancy or difficult.
    I use an XmlTextWriter to rewrite the xml-file. But this is where it gets tricky: the xml-file is stored in a SharePoint Document library, and I need to overwrite the old file there and replace it with the new one.
    For some reason I just can't get this to work! :(

    public void Write()  
                //FileInfo f = new FileInfo();  
                WebClient web = new WebClient();  
                web.Credentials = CredentialCache.DefaultNetworkCredentials;  
                XmlTextWriter w = new XmlTextWriter(this.Page.Request.Url.ToString().Replace("default.aspx""Prince2%20XML/prince2_steps.xml"), null);  
                //w.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");  
                for (int i = 0; i < prince2_treeview.Nodes.Count; i++)  
                    w.WriteAttributeString("name", prince2_treeview.Nodes[i].Value);  
                    w.WriteAttributeString("ouder"" ");  
                    w.WriteAttributeString("checked", prince2_treeview.Nodes[i].Checked.ToString());  
                    for (int j = 0; j < prince2_treeview.Nodes[i].ChildNodes.Count; j++)  
                        w.WriteAttributeString("name", prince2_treeview.Nodes[i].ChildNodes[j].Value);  
                        w.WriteAttributeString("ouder", prince2_treeview.Nodes[i].Value);  
                        w.WriteAttributeString("checked", prince2_treeview.Nodes[i].ChildNodes[j].Checked.ToString());  

    I doesn't give me any trouble with permissions, as it doesn't throw an exception. It doesn't, however, overwrite the existing file.

    Anyone can help?


    Thursday, March 12, 2009 10:59 AM