Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8419347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:35:01+00:00 2026-06-10T02:35:01+00:00

Hello and thanks in advance, I am attempting to take the input from text

  • 0

Hello and thanks in advance,
I am attempting to take the input from text boxes in a silverlight application and on an event fired by a button click, convert them to an xml string, pass the string and a specified file name to a WCF service call and in that call save the xml to the specifed file(via a string parameter). The code which captures the text into an xml string seems to be successfully working(based on what I see in the variables when debugging) and looks like this:

    private void ServerInfoNext_Click(object sender, RoutedEventArgs e)
                {

                    //new RegisterServerGroupObject instance
                    RegisterServerGroupObject groupInfo= new RegisterServerGroupObject(groupNameTB.Text,1,parentServerNameTB.Text,LeaderNameCB.SelectedItem.ToString());

                    var serializer = new XmlSerializer(typeof(RegisterServerGroupObject));
                    XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                    ns.Add("","");

                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Encoding = Encoding.UTF8;
                    settings.Indent = true;
                    settings.CloseOutput = true;

                    StringBuilder sb = new StringBuilder();

                    using (XmlWriter writer = XmlWriter.Create(sb,settings))
                    {
                        serializer.Serialize(writer, groupInfo);
                        writer.Close();
                    }

                    //sb now contains the xml string with the information from the serialized class
                    string contentsString = sb.ToString();
                    //create instance of XmlWrite service
                    XMLWriteServiceClient xmlClient = new XMLWriteServiceClient();
                    xmlClient.WriteXmlToServerCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(xmlClient_WriteXmlToServerCompleted);
                    xmlClient.WriteXmlToServerAsync("ServerGroups.xml", contentsString);
    }

at this point when the variable contents string is passed to the service method, I can see that it has valid xml, as well as within the service method itself, which looks like this:

public class XMLWriteService : IXMLWriteService
    {
        public void WriteXmlToServer(string filename,string xmlString)
        {
            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(xmlString.ToString());


            try
            {
                xDoc.Save(filename);


            }
            catch (FileNotFoundException e)
            {

                Console.WriteLine(e.InnerException.ToString());
            }
        }
    }

The try/catch block is not indicating that the file(“ServerGroups.xml”) is not found, and I currently have that xml file in the ClientBin of the server side portion of the project. (the .Web side). However, after the method terminates there is no new xml written to the file. Can someone please tell me what I am doing wrong? I don’t know why the XmlDocument class instance is not saving its contents to the file. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:35:03+00:00Added an answer on June 10, 2026 at 2:35 am

    You aren’t passing a path, so it’s just going to save the file to the current directory of the WCF service process, whatever that happens to be. Either find out what that is, or do a search on your whole server drive for that file name to see where it’s saving it. Better yet, call Path.Combine to append a path to the begining of the file name before you save to it. For instance:

    xDoc.Save(Path.Combine("C:\\ClientBin", filename));
    

    To answer your question in the comment below, if you want to append the incoming XML data to the data that is already stored in the XML file on the server, that’s a bit more involved. It all depends what the format of the XML is. Since you are using serialization, which by default will only allow one object per XML document (because it puts the object name as the root document element, of which there can only be one), then you would have to have a different XML format. For instance, on the server side, you would need to have some kind of root element on the document under which you could keep appending the incoming RegisterServerGroupObject objects. For instance, if your XML file on the server looked like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <ListOfRegisterServerGroupObject>
    </ListOfRegisterServerGroupObject>
    

    Then, you could append the data by inserting new elements within that root element, like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <ListOfRegisterServerGroupObject>
        <RegisterServerGroupObject>
            ...
        </RegisterServerGroupObject>
        <RegisterServerGroupObject>
            ...
        </RegisterServerGroupObject>
        ...
    </ListOfRegisterServerGroupObject>
    

    To do this, you would need to first load the XML document, then get the root element, then append the incoming XML as a child element. For instance:

    public void WriteXmlToServer(string filename, string xmlString)
    {
        string filePath = Path.Combine("C:\\ClientBin", filename);
        XmlDocument storage = New XmlDocument();
        storage.Load(filePath); 
        XmlDocument incoming = New XmlDocument();
        incoming.LoadXml(xmlString);
        storage.DocumentElement.AppendChild(incoming.DocumentElement);
        storage.Save(filePath);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello and thanks in advance. I am retrieving data from the db. The data
Hello and thanks in advance for any help you can provide. My AIR application
Hello and thanks in advance for you help. I am working with a silverlight
Hello (and thanks in advance) I'm in a bit of a quandry, I cant
I have this kinda template text : Hello {#Name#}, Thanks for coming blah on
Hello and thanks in advance for the communal help I always find here. I
Hello all and thanks in advance I have the tables accounts , votes and
Hello and thanks in advance for taking a look at this. I have discovered
Hello folks and thanks in advance for reading this. I currently use a slider
Hello everyone and thanks in advance for reading this.. I have the following html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.