By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,650 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,650 IT Pros & Developers. It's quick & easy.

Edit text file?

P: n/a
I have a text file which stores user input. Later if user edited the input
data from a input form. How can I update the input text file? If update the
text file too often, would it cause problem?

Thanks in advance for any help.

Nov 21 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
"Nina" <Ni**@discussions.microsoft.com> schrieb:
I have a text file which stores user input. Later if user edited the
input
data from a input form. How can I update the input text file?
For small text files, the simplest solution is to rewrite the whole file.
This doesn't mean deleting the file and then creating a new one, but it
means setting the file's length to 0 using 'FileStream.SetLength' and then
write the data to the file using 'System.IO.StreamWriter'.
If update the text file too often, would it cause problem?


This depends on the size of the file and the intervalls between the updates.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2

P: n/a
Thank you so much for your help. Will 5 to 10 pages's text file be
considered as a small text file?

Nina

"Herfried K. Wagner [MVP]" wrote:
"Nina" <Ni**@discussions.microsoft.com> schrieb:
I have a text file which stores user input. Later if user edited the
input
data from a input form. How can I update the input text file?


For small text files, the simplest solution is to rewrite the whole file.
This doesn't mean deleting the file and then creating a new one, but it
means setting the file's length to 0 using 'FileStream.SetLength' and then
write the data to the file using 'System.IO.StreamWriter'.
If update the text file too often, would it cause problem?


This depends on the size of the file and the intervalls between the updates.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

P: n/a
"Nina" <Ni**@discussions.microsoft.com> schrieb:
Will 5 to 10 pages's text file be
considered as a small text file?


I consider everything < 10 KB a "small file", but that's only my personal
opinion.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

P: n/a
Since the text file that I'm working on is about 50 KB, I cannot use the way
you suggested previously. Is there any way that fits my application?

Thanks again.

Nina

"Herfried K. Wagner [MVP]" wrote:
"Nina" <Ni**@discussions.microsoft.com> schrieb:
Will 5 to 10 pages's text file be
considered as a small text file?


I consider everything < 10 KB a "small file", but that's only my personal
opinion.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OW****************@TK2MSFTNGP14.phx.gbl...
"Nina" <Ni**@discussions.microsoft.com> schrieb:
Will 5 to 10 pages's text file be
considered as a small text file?


I consider everything < 10 KB a "small file", but that's only my personal
opinion.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Herfried --

If the data stored in her file is structured in the

keyname=value

format does VB.Net have a replacement for the old
WritePrivateProfileString and GetPrivateProfileString
API calls? I'm new to .Net and many of my old VB6
programs use these functions to store and update user data.
As I convert the old projects to .Net I'd like to use the
framework if possible.

Jim Edgar
Nov 21 '05 #6

P: n/a
"Nina" <Ni**@discussions.microsoft.com> schrieb:
Since the text file that I'm working on is about 50 KB, I cannot use the
way
you suggested previously. Is there any way that fits my application?


What data are you storing?
How often do you store it?
How often do you read the data?
....

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7

P: n/a
> What data are you storing?
Below is a sample text file:

Subcatchment Name=sub
ID=1
Description=grid
Area=100
Length=800
Slop=4
%Impervious=10
N-Impervious=0.01
N-Pervious=0.05
DStore-Impervious=1.5
Dstore-Pervious=4.5
Model=Horton
End

Statistics
Location=Chicago
Volume=18.86
Duration=7.73
Time=103.1
Annual Number of Events=57.2
End

sub Infil Data
Max. Infil=25.4
Min. Infil=0.36
Decay Constant=4.14
Recovery Constant=0.005
End
How often do you store it?
How often do you read the data? For these two questions, it depends on how often user changes those inputs.
It is possible that user edit those valumes frequently. Well, what I'm trying
to do is to read the text file and put it into a global arraylist when user
opens the project. While user working with the project, I just simply update
the arraylist. When user close the project, then I writ e the arraylist back
to the text file. Do you think this is a good way to handle it?

Thanks again.

Nina

"Herfried K. Wagner [MVP]" wrote:
"Nina" <Ni**@discussions.microsoft.com> schrieb:
Since the text file that I'm working on is about 50 KB, I cannot use the
way
you suggested previously. Is there any way that fits my application?


What data are you storing?
How often do you store it?
How often do you read the data?
....

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8

P: n/a
"Nina" <Ni**@discussions.microsoft.com> schrieb:
What data are you storing?

Below is a sample text file:

Subcatchment Name=sub
ID=1
Description=grid
Area=100
Length=800
Slop=4
%Impervious=10
N-Impervious=0.01
N-Pervious=0.05
DStore-Impervious=1.5
Dstore-Pervious=4.5
Model=Horton
End

Statistics
Location=Chicago
Volume=18.86
Duration=7.73
Time=103.1
Annual Number of Events=57.2
End

sub Infil Data
Max. Infil=25.4
Min. Infil=0.36
Decay Constant=4.14
Recovery Constant=0.005
End
How often do you store it?
How often do you read the data?

For these two questions, it depends on how often user changes those
inputs.
It is possible that user edit those valumes frequently. Well, what I'm
trying
to do is to read the text file and put it into a global arraylist when
user
opens the project. While user working with the project, I just simply
update
the arraylist. When user close the project, then I writ e the arraylist
back
to the text file. Do you think this is a good way to handle it?

I think that's a good way!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9

P: n/a
"Nina" <Ni**@discussions.microsoft.com> schrieb:
What data are you storing?

Below is a sample text file:

Subcatchment Name=sub
ID=1
Description=grid
Area=100
Length=800
Slop=4
%Impervious=10
N-Impervious=0.01
N-Pervious=0.05
DStore-Impervious=1.5
Dstore-Pervious=4.5
Model=Horton
End

Statistics
Location=Chicago
Volume=18.86
Duration=7.73
Time=103.1
Annual Number of Events=57.2
End

sub Infil Data
Max. Infil=25.4
Min. Infil=0.36
Decay Constant=4.14
Recovery Constant=0.005
End
How often do you store it?
How often do you read the data?

For these two questions, it depends on how often user changes those
inputs.
It is possible that user edit those valumes frequently. Well, what I'm
trying
to do is to read the text file and put it into a global arraylist when
user
opens the project. While user working with the project, I just simply
update
the arraylist. When user close the project, then I writ e the arraylist
back
to the text file. Do you think this is a good way to handle it?

I think that's a good way!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #10

P: n/a
Thanks.

"Herfried K. Wagner [MVP]" wrote:
"Nina" <Ni**@discussions.microsoft.com> schrieb:
What data are you storing?

Below is a sample text file:

Subcatchment Name=sub
ID=1
Description=grid
Area=100
Length=800
Slop=4
%Impervious=10
N-Impervious=0.01
N-Pervious=0.05
DStore-Impervious=1.5
Dstore-Pervious=4.5
Model=Horton
End

Statistics
Location=Chicago
Volume=18.86
Duration=7.73
Time=103.1
Annual Number of Events=57.2
End

sub Infil Data
Max. Infil=25.4
Min. Infil=0.36
Decay Constant=4.14
Recovery Constant=0.005
End
How often do you store it?
How often do you read the data?

For these two questions, it depends on how often user changes those
inputs.
It is possible that user edit those valumes frequently. Well, what I'm
trying
to do is to read the text file and put it into a global arraylist when
user
opens the project. While user working with the project, I just simply
update
the arraylist. When user close the project, then I writ e the arraylist
back
to the text file. Do you think this is a good way to handle it?

I think that's a good way!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #11

P: n/a
Thanks.

"Herfried K. Wagner [MVP]" wrote:
"Nina" <Ni**@discussions.microsoft.com> schrieb:
What data are you storing?

Below is a sample text file:

Subcatchment Name=sub
ID=1
Description=grid
Area=100
Length=800
Slop=4
%Impervious=10
N-Impervious=0.01
N-Pervious=0.05
DStore-Impervious=1.5
Dstore-Pervious=4.5
Model=Horton
End

Statistics
Location=Chicago
Volume=18.86
Duration=7.73
Time=103.1
Annual Number of Events=57.2
End

sub Infil Data
Max. Infil=25.4
Min. Infil=0.36
Decay Constant=4.14
Recovery Constant=0.005
End
How often do you store it?
How often do you read the data?

For these two questions, it depends on how often user changes those
inputs.
It is possible that user edit those valumes frequently. Well, what I'm
trying
to do is to read the text file and put it into a global arraylist when
user
opens the project. While user working with the project, I just simply
update
the arraylist. When user close the project, then I writ e the arraylist
back
to the text file. Do you think this is a good way to handle it?

I think that's a good way!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.