none
Check file if exist RRS feed

  • Question

  • How can i insert a code for Info if the file is opened by an other program.                                                                                 dim cse_name as string = sr_name + " output.cse"                                                                                                                if file.exists = true then ...                                                                                                                                                 dim i1 as Integer =mesgbox("..., vbyesno)    endif                                                                                                                                                                                                 

    sw1 = new IO.Streamwriter(cse_name)   -> so here IOException problem if file is opened. How can i solve this problem...  Thanks

    
    
    
    
    
    
    Sunday, September 3, 2017 8:47 PM

All replies

  • Hi lLikePP,

    Assumption (if file was not opened anywhere else) : You open already opened one.Make sure that all your opened streams closed properly. You can use this syntax too.

    Using writer As StreamWriter = New StreamWriter(file)
            writer.Write("....")
               //and so on
    End Using

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Thursday, September 21, 2017 9:49 AM
    Monday, September 4, 2017 7:47 AM
    Moderator
  • How can i insert a code for Info if the file is opened by an other program.  

    You can see this thread : how to check if a file is open in vb.net?
    • Proposed as answer by WayneAKing Tuesday, September 5, 2017 2:55 AM
    Monday, September 4, 2017 7:54 AM

  • Using writer As StreamWriter = New StreamWriter(file)
            writer.Write("....")
               //and so on
    End Using


    This code burns in my eyes, it is a kind of C# code which goes because parts of the code where also in VB7.0

    In VB it is

    using writer as new Streamwriter ...............................................


    Success
    Cor

    Monday, September 4, 2017 8:37 AM
  • You show in your message that you first test if the file exist. 

    It that is not the case it cannot be open in another program. 


    Success
    Cor

    Monday, September 4, 2017 8:39 AM
  • Hi,

    I'm afraid you have shortened or omitted too much of your original code.
    Please provide more precise code.

    Regards,

    Ashidacchi

    Tuesday, September 5, 2017 12:08 AM