none
How do i Save and Load and Online XmlDocument??? RRS feed

  • Question

  • Hey all.
    I Try to load a Online XmlDocument And i succeeded:
    XmlDocument xml =   new XmlDocument();
    xml.Load("https://Somepage/AXmlDocument.xml");

    But my problem is now, after i have edited in the document i cant save it again:
     xml.Save("https://Somepage/AXmlDocument.xml");
    //Makes Exception

    Please help.
    Thanks.

    Friday, June 15, 2012 9:50 AM

Answers

  • The best way is to achieve it through ftp. Set up FTP user credentials and the following code can help you out.

    // Get the object used to communicate with the server.
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
                request.Method = WebRequestMethods.Ftp.UploadFile;
    
                // This example assumes the FTP site uses anonymous logon.
                request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");
                
                // Copy the contents of the file to the request stream.
                StreamReader sourceStream = new StreamReader("testfile.txt");
                byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                sourceStream.Close();
                request.ContentLength = fileContents.Length;
    
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();
    
                FtpWebResponse response = (FtpWebResponse)request.GetResponse();
        
                Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
        
                response.Close();


    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Monday, June 18, 2012 6:50 AM

All replies

  • Can you post an exception.

    You cann't save it directly using the web address. This should be done through FTP may be. Check your hosting admin for rights


    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Friday, June 15, 2012 10:36 AM
  • The given Exception is:
    The given path's format is not supported.

    Sow i also guessed, that it should be done in another way,
    Thanks for the advice abut FTP,
    but can you give an exempel, ore a link??

    Saturday, June 16, 2012 9:07 AM
  • You probably don't have the permission to write the data using https.  Try the change below.  Depedning on your access rights to the folder you may or may not be able to save.

    Frpm : xml.Save("https://Somepage/AXmlDocument.xml");

    To : xml.Save("file://Somepage/AXmlDocument.xml");


    jdweng

    Saturday, June 16, 2012 9:45 AM
  • It didn't work.... Still same Exception. But thanks for the try.
    Can it be done in another way???
    The idea is, that the program shall load and save all its data online,
    so if you start the program on another computer, it still have all its data.
    Can i use a MySQL-database??


    • Edited by Lynspitti Monday, June 18, 2012 6:30 AM
    Monday, June 18, 2012 6:22 AM
  • The best way is to achieve it through ftp. Set up FTP user credentials and the following code can help you out.

    // Get the object used to communicate with the server.
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
                request.Method = WebRequestMethods.Ftp.UploadFile;
    
                // This example assumes the FTP site uses anonymous logon.
                request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");
                
                // Copy the contents of the file to the request stream.
                StreamReader sourceStream = new StreamReader("testfile.txt");
                byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                sourceStream.Close();
                request.ContentLength = fileContents.Length;
    
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();
    
                FtpWebResponse response = (FtpWebResponse)request.GetResponse();
        
                Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
        
                response.Close();


    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Monday, June 18, 2012 6:50 AM