Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Save XML

Save XML

Scheduled Pinned Locked Moved C#
xmltutorial
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NarVish
    wrote on last edited by
    #1

    Hi, After modifying the content in xml file, I tried to save in the same location. It is throwing an exception that the file is already in use. So unable to save in the same location. When I tried to save in the other location, its working fine. Please guide me to save in the same path. thanks in advance.

    string filePath="C:\\test\\sample.xml";
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(filePath);

    //made some changes in xmlDoc

    xmlDoc.Save(filePath); //exception

    I S 2 Replies Last reply
    0
    • N NarVish

      Hi, After modifying the content in xml file, I tried to save in the same location. It is throwing an exception that the file is already in use. So unable to save in the same location. When I tried to save in the other location, its working fine. Please guide me to save in the same path. thanks in advance.

      string filePath="C:\\test\\sample.xml";
      XmlDocument xmlDoc = new XmlDocument();
      xmlDoc.Load(filePath);

      //made some changes in xmlDoc

      xmlDoc.Save(filePath); //exception

      I Offline
      I Offline
      Ice_Freez05
      wrote on last edited by
      #2

      try renaming the modified xml document.like original filename + date modified.

      N 1 Reply Last reply
      0
      • I Ice_Freez05

        try renaming the modified xml document.like original filename + date modified.

        N Offline
        N Offline
        NarVish
        wrote on last edited by
        #3

        Its like creating a new file. Isn't there a way to replace the file?

        1 Reply Last reply
        0
        • N NarVish

          Hi, After modifying the content in xml file, I tried to save in the same location. It is throwing an exception that the file is already in use. So unable to save in the same location. When I tried to save in the other location, its working fine. Please guide me to save in the same path. thanks in advance.

          string filePath="C:\\test\\sample.xml";
          XmlDocument xmlDoc = new XmlDocument();
          xmlDoc.Load(filePath);

          //made some changes in xmlDoc

          xmlDoc.Save(filePath); //exception

          S Offline
          S Offline
          surender m
          wrote on last edited by
          #4

          Hi Narvish, There is no problem with code, the same is worked for me. i would suggest to make the document object null in finally block. In your case the worker process might be using the file in memory. Regards Surender No Defeat Is Final Until You Stop Trying!.......

          N 1 Reply Last reply
          0
          • S surender m

            Hi Narvish, There is no problem with code, the same is worked for me. i would suggest to make the document object null in finally block. In your case the worker process might be using the file in memory. Regards Surender No Defeat Is Final Until You Stop Trying!.......

            N Offline
            N Offline
            NarVish
            wrote on last edited by
            #5

            As per your suggestion, I kept the code in try block and I added

            finally
            {
            xmlDoc = null;
            }

            Still it is throwing exception that process cannot use that file.. because it is using by other thread. :(

            S 1 Reply Last reply
            0
            • N NarVish

              As per your suggestion, I kept the code in try block and I added

              finally
              {
              xmlDoc = null;
              }

              Still it is throwing exception that process cannot use that file.. because it is using by other thread. :(

              S Offline
              S Offline
              surender m
              wrote on last edited by
              #6

              Make sure the file and folder have proper permissions set and file is not kept open anywhere. remove file manually and try again. Regards Surender No Defeat Is Final Until You Stop Trying!.......

              N 1 Reply Last reply
              0
              • S surender m

                Make sure the file and folder have proper permissions set and file is not kept open anywhere. remove file manually and try again. Regards Surender No Defeat Is Final Until You Stop Trying!.......

                N Offline
                N Offline
                NarVish
                wrote on last edited by
                #7

                yes, thats the problem with the file. I copied the file with other name and used it. it worked fine. Thank you

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups