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. how to read a file content, that file was already opened ?

how to read a file content, that file was already opened ?

Scheduled Pinned Locked Moved C#
tutorialquestion
7 Posts 2 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.
  • C Offline
    C Offline
    CooperWu
    wrote on last edited by
    #1

    I try these code, but doesn't work, string file = @"e:\test.log"; FileStream fs1 = new FileStream(file, FileMode.Append, FileAccess.Write, FileShare.Read); FileStream fs2 = new FileStream(file, FileMode.Open, FileAccess.Read); throw an exception: System.IO.IOException: The process cannot access the file 'e:\test.log' because it is being used by another process.. how to solve this?

    Glad to discuss with you and best wishes.

    X 1 Reply Last reply
    0
    • C CooperWu

      I try these code, but doesn't work, string file = @"e:\test.log"; FileStream fs1 = new FileStream(file, FileMode.Append, FileAccess.Write, FileShare.Read); FileStream fs2 = new FileStream(file, FileMode.Open, FileAccess.Read); throw an exception: System.IO.IOException: The process cannot access the file 'e:\test.log' because it is being used by another process.. how to solve this?

      Glad to discuss with you and best wishes.

      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #2

      FileStream fs1 = new FileStream(file, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
      FileStream fs2 = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

      TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

      C 1 Reply Last reply
      0
      • X Xmen Real

        FileStream fs1 = new FileStream(file, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
        FileStream fs2 = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

        C Offline
        C Offline
        CooperWu
        wrote on last edited by
        #3

        thanks for your reply, i have tried this, throw the same exception. i nearly tried all 'FileAccess', 'FileShare' combination :(

        Glad to discuss with you and best wishes.

        X 1 Reply Last reply
        0
        • C CooperWu

          thanks for your reply, i have tried this, throw the same exception. i nearly tried all 'FileAccess', 'FileShare' combination :(

          Glad to discuss with you and best wishes.

          X Offline
          X Offline
          Xmen Real
          wrote on last edited by
          #4

          well, I check this and its working without any error

          TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

          C 2 Replies Last reply
          0
          • X Xmen Real

            well, I check this and its working without any error

            TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

            C Offline
            C Offline
            CooperWu
            wrote on last edited by
            #5

            Sorry for my mistake, i create a test project like the first message, and it works. but in my real project, it always throw the exception... I wrote a singleton mode class, Logger class, to write log to file. This logger class has 'LogLevel' property, the actions like in log4net. then, i wrote a unit test class to test its LogLevel property setting will work. ... I use the first FileStream in Logger class, then I use the second FileStream in Logger Unit Test class, to check log message is corrent. ... the second FileStream always throw that exception. :(

            Glad to discuss with you and best wishes.

            1 Reply Last reply
            0
            • X Xmen Real

              well, I check this and its working without any error

              TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

              C Offline
              C Offline
              CooperWu
              wrote on last edited by
              #6

              thanks, i fixed it with your help. i debug the code very carefully, find the exception was throw by next sentence. StreamReader reader = new StreamReader(fileStream); but not new FileStream(), so i changed StreamReader to fileStream.GetByte(..) then it works. :rose::rose::rose:

              Glad to discuss with you and best wishes.

              X 1 Reply Last reply
              0
              • C CooperWu

                thanks, i fixed it with your help. i debug the code very carefully, find the exception was throw by next sentence. StreamReader reader = new StreamReader(fileStream); but not new FileStream(), so i changed StreamReader to fileStream.GetByte(..) then it works. :rose::rose::rose:

                Glad to discuss with you and best wishes.

                X Offline
                X Offline
                Xmen Real
                wrote on last edited by
                #7

                glad, you got it work ;)

                TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                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