Results 1 to 2 of 2

Thread: How do I close a text file???

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jul 2002
    Posts
    80

    Question How do I close a text file???

    I have a web form that allows users to upload text files to the web server then my code opens the text file and stores the data to a database. That all works. However, if the text file is not in the correct format, I allow the user to fix the text file and try to upload again. My problem is I don't know how to close the text file. When the user try to upload again I receive the following error. I believe it's because the file is still open and locked.

    Access to the path "c:\inetpub\wwwroot\WylePricingSystem\WeeklyLaborArchive\BAWeeklyHours050403.txt" is denied.

    I tried to fix my problem by catching the error, then trying to close the objStreamReader hoping it would close the file so I can delete it.

    Does anyone know how I can solve my problem? Look below at what I trying to do.

    Dim myFileName as string
    Dim objStreamReader As StreamReader

    myFileName=session("filename")
    try

    objStreamReader = File.OpenText("c:\inetpub\wwwroot\WylePricingSystem\WeeklyLaborArchive\" + myFileName)
    .
    .
    .
    catch err As Exception
    Response.Write("<BR>")
    Response.Write(err.Message.ToString)
    objStreamReader.DiscardBufferedData()
    objStreamReader.Close()


    File.Delete("c:\inetpub\wwwroot\WylePricingSystem\WeeklyLaborArchive\" + myFileName)
    End Try

    Thanks,

    James

  2. #2
    Member
    Join Date
    Mar 2003
    Posts
    33
    why don 't you use xml files for uploading, then you don't have
    to worrie about the format any longer.
    You can make a form which users can use to write xml files
    in the format you want (use a xmlwriter)

    then you can read the xmfiles and put them in any kind of datastore you want.

    Krol

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