473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Having a hard time trying to open a text file

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 13 '06 #1
13 1226
"Tony Girgenti" <tony(nospam)@lakesideos.comwrote in message
news:uz**************@TK2MSFTNGP05.phx.gbl...
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
Sep 13 '06 #2
Hello John.

I copied everything from here:
http://msdn.microsoft.com/library/de.../vastmOpen.asp

Thanks,
Tony

"John Saunders" <john.saunders at trizetto.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Tony Girgenti" <tony(nospam)@lakesideos.comwrote in message
news:uz**************@TK2MSFTNGP05.phx.gbl...
>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


Sep 13 '06 #3
"Tony Girgenti" <tony(nospam)@lakesideos.comwrote in message
news:Oo**************@TK2MSFTNGP05.phx.gbl...
Hello John.

I copied everything from here:
http://msdn.microsoft.com/library/de.../vastmOpen.asp
I see. I've never used these. Good luck.

John
Sep 13 '06 #4
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
-------------------
Sep 14 '06 #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)"
<ga*****************@nospam.gmail.comwrote in message
news:e7**************@TK2MSFTNGP04.phx.gbl...
>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
-------------------


Sep 14 '06 #6
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
-------------------
Sep 15 '06 #7
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)"
<ga*****************@nospam.gmail.comwrote in message
news:eh**************@TK2MSFTNGP04.phx.gbl...
>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
-------------------


Sep 15 '06 #8
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 '06 #9
>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
-------------------
Sep 17 '06 #10
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)"
<ga*****************@nospam.gmail.comwrote in message
news:eu**************@TK2MSFTNGP04.phx.gbl...
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
-------------------


Sep 17 '06 #11
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/de...mpfilename.asp

When the system shuts down, temporary files whose names have been created by
this function are not automatically deleted.

--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.com
http://www.edujinionline.com
http://articles.edujinionline.com/webservices
-------------------
Sep 17 '06 #12
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)"
<ga*****************@nospam.gmail.comwrote in message
news:uI**************@TK2MSFTNGP06.phx.gbl...
>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/de...mpfilename.asp

When the system shuts down, temporary files whose names have been created
by this function are not automatically deleted.


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.com
http://www.edujinionline.com
http://articles.edujinionline.com/webservices
-------------------


Sep 18 '06 #13
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 ?
Strictly speaking, all that is required is a valid, random, new name.
You have the following options:

1. Generate yourself
2. Ask somebody to generate
2a. Use GetTempFileName
2b. Directly invoke GetTempFileName since it can work with
non-GetTempPath folders as well.

--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.com
http://www.edujinionline.com
http://articles.edujinionline.com/webservices
-------------------
Sep 19 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: malcolm | last post by:
Hello, We have a small team building a project that involves some 30 or so c# assembly dlls. It is a client server application with 1 exe as the starting point. The dlls and exe are sharing an...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
3
by: sparks | last post by:
I am building a web ap and have a webform1 an agreement.cs and a files.cs going to an access database I am not having problems reading or writing to the database but I have hit a snag on how to keep...
1
by: Ruy Castelli | last post by:
I created a ASP.NET page using C# and I'm using two components to access a MS-Access database, which are: - oleDbConnection - oleDataAdapter The MS-Access database is in the correct directory...
1
by: KShapiro | last post by:
Hi All, I am trying to assist my wife, by making a simple menu system for the website. The web page is a .php4 file and does an include of the navigation file. Before it includes that file at...
13
by: Tony Girgenti | last post by:
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...
0
by: Tony Girgenti | last post by:
Hello. I developed and tested a web application using VS.NET 2003, VB, .NET Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1. It uses a web form. I'm having the darndest time trying to make...
13
by: ragtag99 | last post by:
I posted this on comp.lang.asm.x86, alt.os.development, comp.arch, comp.lang.c++ Im working with windows xp professional, NTFS and programming with MASM, c++ (free compiler) or visual basic 6.0...
0
grassh0pp3r
by: grassh0pp3r | last post by:
Hello, I'm trying to make a very simple comments page on my site using PHP and am having problems somewhere. I am very new to PHP. I was able to create one that works with comments appended, but...
8
by: sabby | last post by:
I want to use the getline() so that i can enter a entire name in on line. (with spaces) The prob is that i am initializing the variable as "N/A" and saving it to a text file. it is declared as a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.