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 8595281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:23:51+00:00 2026-06-12T00:23:51+00:00

I am a new to Programming. I am creating a XML file using windows

  • 0

I am a new to Programming. I am creating a XML file using windows forms and the name of my XML file is the name field text-box text of windows forms, Its working fine but if the file is already available i want to give new name but i am able to give different name only once. For example if ‘dog.xml’ is already there then i am able to create dog1.xml file then whenever i am creating any new file the content of the ‘dog1.xml’ file replaced with new file content but i want to create ‘dog11.xml’ or ‘dog2.xml’ file

private void btnSave_Click(object sender, EventArgs e)
{
    path = rtxtName.Text + ".xml";//name of a xml file is name of WPF 'name' field 
    doc = new XmlDocument(); //Here i am creating the xmldocument object
    doc.CreateTextNode(path);
    if (!System.IO.File.Exists(path))//if there is no file exists then
    {
        CreateNewXMLDoc();
    }
    else
    {
        path = rtxtName.Text + "1.xml"; //If the file is already avaliable          
        CreateNewXMLDoc();
    }
}

public void CreateNewXMLDoc() //This method is for creating my xml file
{
    XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
    XmlComment comment = doc.CreateComment("This is a generated XML file");
    doc.AppendChild(declaration);
    doc.AppendChild(comment);
    doc.AppendChild(doc.CreateElement("root"));
}
  • 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-12T00:23:52+00:00Added an answer on June 12, 2026 at 12:23 am
        private void btnSave_Click(object sender, EventArgs e)
        {
            path = rtxtName.Text;//name of a xml file is name of WPF 'name' field 
    
            doc = new XmlDocument(); //Here i am creating the xmldocument object
    
            string tempPath = path;
            int counter = Properties.Settings.Default.Counter;
    
            while(System.IO.File.Exists(tempPath))
            {
                counter++;
                tempPath = path + counter + ".xml";
            }
    
            Properties.Settings.Default.Counter = counter;
            Properties.Settings.Default.Save();
            doc.CreateTextNode(path);
            CreateNewXMLDoc();
        }
    

    If you would like to be fancy and follow Microsofts standards, then change the path to this
    you can build in the something – Copy.xml then something – Copy (1).xml, etc.

    tempPath = path + "(" + counter + ")" + ".xml";
    

    EDIT

    Updated to keep the counter when the application restarts

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to programming, and I'm creating a simple text-based game.> I'm wondering
What is the real benefit of creating a new programming language? It is highly
I'm really new to programming, and creating programs. Recently I was browsing around iTunes
First off I'm new at programming. I'm creating an app with one navigation bar
I'm new to Mac programming and I'm working on a document-based application. My NSDocument
I am new to programming and this is creating a lot of confusion for
I'm relative new to android programming and layouts, and got stuck on creating a
I am a new Database programming learner. I am using C# (.NET 3.5) along
I am fairly new to programming and I'm creating a form that transitions, yet
Im just new to MySql Programming and Im creating a project to enchance my

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.