Results 1 to 5 of 5

Thread: [2005] [error in file close]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    98

    Resolved [2005] [error in file close]

    hi friends,

    In first line i gave the code like this
    File.Create(txtbox1.text+".txt");

    next line i gave
    file.delete(txtbox1.text+".txt");

    but it shows the error
    " file is used by another process"

    how to close the file
    Last edited by manju.cdtech; Mar 27th, 2007 at 12:34 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] [error in file close]

    File.Create returns a FileStream object. You need to call the Close method of that object. If you don't assign the return value of File.Create to a variable then you have no access to that FileStream object so you have no way of closing the file. Always read the documentation for the types and members that you're using. The doco for the File.Create has a code example of just that so you wouldn't have had to ask.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] [error in file close]

    vb Code:
    1. Try
    2.             Dim fileStream As FileStream
    3.             fileStream = System.IO.File.Create("E:\Text1.txt")
    4.             fileStream.Close()
    5.             'For Deleting
    6.             System.IO.File.Delete("E:\Text1.txt")
    7.         Catch ex As Exception
    8.  
    9.         End Try

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    98

    Re: [2005] [error in file close]

    Thanks for your help ...

  5. #5
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] [error in file close]

    Quote Originally Posted by manju.cdtech
    Thanks for your help ...
    Your welcome

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width