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. Strange Problem at writing file

Strange Problem at writing file

Scheduled Pinned Locked Moved C#
helpquestionxml
14 Posts 4 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.
  • E error1408

    I did not post any code.

    S Offline
    S Offline
    Spacix One
    wrote on last edited by
    #4

    Ah, just looked like you did. is this being done in < .NET 2.0?


    -Spacix All your skynet questions[^] belong to solved

    E 1 Reply Last reply
    0
    • S Spacix One

      Ah, just looked like you did. is this being done in < .NET 2.0?


      -Spacix All your skynet questions[^] belong to solved

      E Offline
      E Offline
      error1408
      wrote on last edited by
      #5

      Yes .Net 2, i tried to convert and compile it with .net 3 but same thing happened.

      S 1 Reply Last reply
      0
      • E error1408

        Yes .Net 2, i tried to convert and compile it with .net 3 but same thing happened.

        S Offline
        S Offline
        Spacix One
        wrote on last edited by
        #6

        Are you using the old xmlreader and xmlwriter? If not then why do you "open, read, close" then "open, write, close" ?


        -Spacix All your skynet questions[^] belong to solved

        E 1 Reply Last reply
        0
        • S Spacix One

          Are you using the old xmlreader and xmlwriter? If not then why do you "open, read, close" then "open, write, close" ?


          -Spacix All your skynet questions[^] belong to solved

          E Offline
          E Offline
          error1408
          wrote on last edited by
          #7

          I'm using the xmlDocument Class. When i want to save with xmlDocument.save() that error happens

          J S 2 Replies Last reply
          0
          • E error1408

            I'm using the xmlDocument Class. When i want to save with xmlDocument.save() that error happens

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #8

            Im willing to bet that you've not disposed properly of the stream when you open the file, hence when you come to write it there is already another process holding onto it (ie, your own program from earlier on during the read op)

            --- How to get answers to your questions[^]

            E 1 Reply Last reply
            0
            • J J4amieC

              Im willing to bet that you've not disposed properly of the stream when you open the file, hence when you come to write it there is already another process holding onto it (ie, your own program from earlier on during the read op)

              --- How to get answers to your questions[^]

              E Offline
              E Offline
              error1408
              wrote on last edited by
              #9

              Thats not the case, because it does not happen at all if i don't open the explorer and look into that folder.

              1 Reply Last reply
              0
              • E error1408

                I'm using the xmlDocument Class. When i want to save with xmlDocument.save() that error happens

                S Offline
                S Offline
                Spacix One
                wrote on last edited by
                #10

                once you call the load() method the file should no longer be accessed... Again I don't see why you "open, load, close" then "open, write, close" You should be fine with it in ram after you load it. "open, load" do your other stuff "append new data, close"


                -Spacix All your skynet questions[^] belong to solved

                E 1 Reply Last reply
                0
                • S Spacix One

                  once you call the load() method the file should no longer be accessed... Again I don't see why you "open, load, close" then "open, write, close" You should be fine with it in ram after you load it. "open, load" do your other stuff "append new data, close"


                  -Spacix All your skynet questions[^] belong to solved

                  E Offline
                  E Offline
                  error1408
                  wrote on last edited by
                  #11

                  I tried it. But it doesn't have an effect. Here is my code at the moment:

                  //some loop
                  XmlDocument doc = new XmlDocument();
                  doc.Load(FullFilePath);
                  .......//do sth.
                  doc.Save(FullFilePath); //<-There the error happens
                  //end of loop

                  S L 2 Replies Last reply
                  0
                  • E error1408

                    I tried it. But it doesn't have an effect. Here is my code at the moment:

                    //some loop
                    XmlDocument doc = new XmlDocument();
                    doc.Load(FullFilePath);
                    .......//do sth.
                    doc.Save(FullFilePath); //<-There the error happens
                    //end of loop

                    S Offline
                    S Offline
                    Spacix One
                    wrote on last edited by
                    #12

                    Does it error if you try to write to a different file path? (one you know you have write access to)


                    -Spacix All your skynet questions[^] belong to solved

                    1 Reply Last reply
                    0
                    • E error1408

                      I tried it. But it doesn't have an effect. Here is my code at the moment:

                      //some loop
                      XmlDocument doc = new XmlDocument();
                      doc.Load(FullFilePath);
                      .......//do sth.
                      doc.Save(FullFilePath); //<-There the error happens
                      //end of loop

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #13

                      Hi, if you want write or delete access (anything other than read access) to a file that just got created (by yourself or someone else, does not matter), chances are you will find the file is being accessed by some other process, and your access is not granted. Yhe other process very likely is some server code that is there to assist you somehow. Candidates are: - anti-virus software (Norton, McAfee, whatever) - indexing software (Google Desktop, MS Office, whatever) The common thing is these packages are looking all the time for new files, so they can inspect them. Microsoft is aware of the consequences; Windows Explorer will try rename and delete attempts up to five times (with one second interval), and only reports failure if the action continues to fail for that time. The solution: 1. either use a different file name 2. or remove all background reader candidates (bad idea) 3. or implement the retry loop as Explorer has it (use a Windows.Forms.Timer for this) :)

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


                      E 1 Reply Last reply
                      0
                      • L Luc Pattyn

                        Hi, if you want write or delete access (anything other than read access) to a file that just got created (by yourself or someone else, does not matter), chances are you will find the file is being accessed by some other process, and your access is not granted. Yhe other process very likely is some server code that is there to assist you somehow. Candidates are: - anti-virus software (Norton, McAfee, whatever) - indexing software (Google Desktop, MS Office, whatever) The common thing is these packages are looking all the time for new files, so they can inspect them. Microsoft is aware of the consequences; Windows Explorer will try rename and delete attempts up to five times (with one second interval), and only reports failure if the action continues to fail for that time. The solution: 1. either use a different file name 2. or remove all background reader candidates (bad idea) 3. or implement the retry loop as Explorer has it (use a Windows.Forms.Timer for this) :)

                        Luc Pattyn [Forum Guidelines] [My Articles]


                        this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


                        E Offline
                        E Offline
                        error1408
                        wrote on last edited by
                        #14

                        Thank you very much.

                        Luc Pattyn wrote:

                        The solution: 1. either use a different file name 2. or remove all background reader candidates (bad idea) 3. or implement the retry loop as Explorer has it (use a Windows.Forms.Timer for this)

                        1. and 2. are no solutions for me. I have to try 3. I think. I hoped i don't have to use a timer :(

                        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