Having a hard time trying to open a text file

Discussion in 'ASP .Net Web Services' started by Tony Girgenti, Sep 13, 2006.

  1. Hello.

    I developed a web consuming windows application/form program with VS.NET
    2003, VB, .Net Framework 1.1.4322, ASP.NET 1.1.4322, IIS 5.1.

    Using this code to open a simple text file. If i get an error in my program
    after the file has been opened once, it gives me a message saying
    "System.IO.IOException: File already open."

    FileOpen(1, "C:\xmltrips.txt", OpenMode.Output, OpenAccess.Write)

    WriteLine(1, txtFilStr)

    When i try to delete it, it says "It is being used by another person or
    program".

    If it's being opened output, then why won't it open again and again ?

    I have a FileClose(1) in the catch statement.

    Any help would be gratefully appreciated.

    Thanks,
    Tony
    Tony Girgenti, Sep 13, 2006
    #1
    1. Advertising

  2. "Tony Girgenti" <tony(nospam)@lakesideos.com> wrote in message
    news:...
    > Hello.
    >
    > I developed a web consuming windows application/form program with VS.NET
    > 2003, VB, .Net Framework 1.1.4322, ASP.NET 1.1.4322, IIS 5.1.
    >
    > Using this code to open a simple text file. If i get an error in my
    > program after the file has been opened once, it gives me a message saying
    > "System.IO.IOException: File already open."
    >
    > FileOpen(1, "C:\xmltrips.txt", OpenMode.Output, OpenAccess.Write)
    >
    > WriteLine(1, txtFilStr)
    >
    > When i try to delete it, it says "It is being used by another person or
    > program".
    >
    > If it's being opened output, then why won't it open again and again ?
    >
    > I have a FileClose(1) in the catch statement.
    >
    > Any help would be gratefully appreciated.


    What are FileOpen and FileClose? I don't recognize them

    John
    John Saunders, Sep 13, 2006
    #2
    1. Advertising

  3. Hello John.

    I copied everything from here:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmOpen.asp

    Thanks,
    Tony

    "John Saunders" <john.saunders at trizetto.com> wrote in message
    news:%...
    > "Tony Girgenti" <tony(nospam)@lakesideos.com> wrote in message
    > news:...
    >> Hello.
    >>
    >> I developed a web consuming windows application/form program with VS.NET
    >> 2003, VB, .Net Framework 1.1.4322, ASP.NET 1.1.4322, IIS 5.1.
    >>
    >> Using this code to open a simple text file. If i get an error in my
    >> program after the file has been opened once, it gives me a message saying
    >> "System.IO.IOException: File already open."
    >>
    >> FileOpen(1, "C:\xmltrips.txt", OpenMode.Output, OpenAccess.Write)
    >>
    >> WriteLine(1, txtFilStr)
    >>
    >> When i try to delete it, it says "It is being used by another person or
    >> program".
    >>
    >> If it's being opened output, then why won't it open again and again ?
    >>
    >> I have a FileClose(1) in the catch statement.
    >>
    >> Any help would be gratefully appreciated.

    >
    > What are FileOpen and FileClose? I don't recognize them
    >
    > John
    >
    >
    Tony Girgenti, Sep 13, 2006
    #3
  4. John Saunders, Sep 13, 2006
    #4
  5. Hell Gaurav.

    If i use a database, how would i get the data from the database to the
    mainframe ?

    Thanks,
    Tony

    "Gaurav Vaish (www.EduJiniOnline.com)"
    <> wrote in message
    news:...
    >> Using this code to open a simple text file. If i get an error in my
    >> program after the file has been opened once, it gives me a message saying
    >> "System.IO.IOException: File already open."

    >
    > Thru a web-service?
    >
    > Well, probably, multiple requests on the Web-Service is causing the error.
    >
    > I would suggest using database rather than files to avoid concurrency
    > issues.
    >
    >
    >
    > --
    > Happy Hacking,
    > Gaurav Vaish | http://www.mastergaurav.com
    > http://www.edujinionline.com
    > http://articles.edujinionline.com/webservices
    > -------------------
    >
    >
    Tony Girgenti, Sep 14, 2006
    #5
  6. I guess my point is, if i can't use a file in my web application to capture
    the data during program operation, then how will i create and use a file in
    my web application taking the data from the database. In other words,
    what's the difference whether i create the file during program operation or
    whether it creates the file afterwards reading from the database ?

    Thanks,
    Tony

    "Gaurav Vaish (www.EduJiniOnline.com)"
    <> wrote in message
    news:...
    >> If i use a database, how would i get the data from the database to the
    >> mainframe ?

    >
    > Same way as you would do from the file.
    > Or do you have the file on the MainFrame?
    >
    > If so, you may install MSDE on the machine with .Net.
    > Make a simple table with only one field -- say, contents of type, may
    > be, blob.
    > Push all the contents in field as what you would push in the file.
    >
    > This is the simplest way that you may leave the file and use database.
    > If the content in file is structured, you may created more fields in
    > database.
    >
    >
    > --
    > Happy Hacking,
    > Gaurav Vaish | http://www.mastergaurav.com
    > http://www.edujinionline.com
    > http://articles.edujinionline.com/webservices
    > -------------------
    >
    >
    Tony Girgenti, Sep 15, 2006
    #6
  7. Tony Girgenti

    Guest

    You may want to try including OpenShare.Shared when you make your
    FileOpen() call. The system may grant you shared access to the file,
    depending on what the other process is that has previously accessed it.

    Tony Girgenti (nospam) wrote:
    > Hello.
    >
    > I developed a web consuming windows application/form program with VS.NET
    > 2003, VB, .Net Framework 1.1.4322, ASP.NET 1.1.4322, IIS 5.1.
    >
    > Using this code to open a simple text file. If i get an error in my program
    > after the file has been opened once, it gives me a message saying
    > "System.IO.IOException: File already open."
    >
    > FileOpen(1, "C:\xmltrips.txt", OpenMode.Output, OpenAccess.Write)
    >
    > WriteLine(1, txtFilStr)
    >
    > When i try to delete it, it says "It is being used by another person or
    > program".
    >
    > If it's being opened output, then why won't it open again and again ?
    >
    > I have a FileClose(1) in the catch statement.
    >
    > Any help would be gratefully appreciated.
    >
    > Thanks,
    > Tony
    , Sep 16, 2006
    #7
  8. Gaurav.

    Now that i have spent two days trying to figure out how to use a
    dataset/database to put my data into, i'm not sure i want to go back to
    using a flat text file.

    Does thae fact that GetTempFileName has the word "Temp" in it tell me
    anything. Should i wonder if the file will remain after the program
    terminates ?

    Thanks,
    Tony

    "Gaurav Vaish (www.EduJiniOnline.com)"
    <> wrote in message
    news:...
    > >I guess my point is, if i can't use a file in my web application to
    > >capture the data during program operation, then how will i create and use
    > >a file in my web application taking the data from the database. In other
    > >words, what's the difference whether i create the file during program
    > >operation or whether it creates the file afterwards reading from the
    > >database ?

    >
    > Oh!
    > I thought the otherwise.... that you are using file to read the data from
    > :)
    >
    > In that case, you may create a temporary file with a random name.
    > System.IO.Path.GetTempFileName method
    >
    > Push all open/write in a try block.
    > Have the 'Close' in 'finally' block.
    >
    > HTH
    >
    > --
    > Happy Hacking,
    > Gaurav Vaish | http://www.mastergaurav.com
    > http://www.edujinionline.com
    > http://articles.edujinionline.com/webservices
    > -------------------
    >
    >
    Tony Girgenti, Sep 17, 2006
    #8
  9. Considering this, since i want the file to be available after the program
    terminates, i don't think i should use this method to store my data. Even
    though the file is not automatically deleted.

    Do you agree ?

    Thanks,
    Tony

    "Gaurav Vaish (www.EduJiniOnline.com)"
    <> wrote in message
    news:...
    >> Does thae fact that GetTempFileName has the word "Temp" in it tell me
    >> anything. Should i wonder if the file will remain after the program
    >> terminates ?

    >
    > Yes.
    > The folder in which it is created is always Path.GetTempPath
    > The name is randomly chosen so that it is unique.
    > The extension is always .tmp
    > The prefix is always tmp
    > The file is not temporary in the sense that it is not automatically
    > deleted.
    >
    >
    > The method is a wrapper around the native method GetTempFileName.
    > The details of the native method is available at:
    > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/gettempfilename.asp
    >
    >
    >
    >
    > --
    > Happy Hacking,
    > Gaurav Vaish | http://www.mastergaurav.com
    > http://www.edujinionline.com
    > http://articles.edujinionline.com/webservices
    > -------------------
    >
    >
    Tony Girgenti, Sep 18, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dennis
    Replies:
    0
    Views:
    569
    dennis
    May 23, 2006
  2. Tony Girgenti

    Having a hard time trying to open a text file

    Tony Girgenti, Sep 13, 2006, in forum: ASP .Net
    Replies:
    13
    Views:
    572
    Gaurav Vaish \(www.EduJiniOnline.com\)
    Sep 19, 2006
  3. Nate Imaqaguy
    Replies:
    29
    Views:
    283
  4. Yves S. Garret
    Replies:
    0
    Views:
    140
    Yves S. Garret
    Mar 16, 2013
  5. Yves S. Garret
    Replies:
    2
    Views:
    115
Loading...

Share This Page