I have a simple form with a multiline Textbox.
I load the textbox with the contents of a text file.
I make changes to the textbox, then I attempt to OVERWRITE the original
file.
I have tried opening with FilMode.Create, FileMode.Truncate but they
bothh APPEND to the file.
What is the correct syntax for Overwriting - Thanks for any help
My Code is as follows:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strFname As String = DropDownList1.SelectedItem.Text
lblDebug.Text += "LoadButton: " &
DropDownList1.SelectedItem.Text & "<BR />"
Dim fw As New System.IO.StreamReader(Server.MapPath("MyData/" &
strFname), True)
TextBox1.Text = fw.ReadToEnd()
fw.Close()
fw.Dispose()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim strFname As String = DropDownList1.SelectedItem.Text
lblDebug.Text += "UpdateButton: " &
DropDownList1.SelectedItem.Text & "<BR />"
Dim fw As New System.IO.StreamWriter(Server.MapPath("MyData/" &
strFname), System.IO.FileMode.Create)
fw.Write(TextBox1.Text)
fw.Close()
fw.Dispose()
End Sub 2 10361
Create StreamWriter instance with "False" for the second ctor argument. It
specifies if data is appended (True means Append, False means overwrite or
create a new file)
Dim fw As New System.IO.StreamWriter(Server.MapPath("MyData/" & strFname),
False)
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU http://blogs.aspadvice.com/joteke
"mosscliffe" <pa***********@googlemail.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com... I have a simple form with a multiline Textbox.
I load the textbox with the contents of a text file.
I make changes to the textbox, then I attempt to OVERWRITE the original file.
I have tried opening with FilMode.Create, FileMode.Truncate but they bothh APPEND to the file.
What is the correct syntax for Overwriting - Thanks for any help
My Code is as follows:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strFname As String = DropDownList1.SelectedItem.Text lblDebug.Text += "LoadButton: " & DropDownList1.SelectedItem.Text & "<BR />" Dim fw As New System.IO.StreamReader(Server.MapPath("MyData/" & strFname), True) TextBox1.Text = fw.ReadToEnd() fw.Close() fw.Dispose()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Dim strFname As String = DropDownList1.SelectedItem.Text lblDebug.Text += "UpdateButton: " & DropDownList1.SelectedItem.Text & "<BR />" Dim fw As New System.IO.StreamWriter(Server.MapPath("MyData/" & strFname), System.IO.FileMode.Create) fw.Write(TextBox1.Text) fw.Close() fw.Dispose()
End Sub
Thank You - tracking down the exact Syntax, can be difficult at times.
I am always grateful to the people, who help in this newsgroup.
Teemu Keiski wrote: Create StreamWriter instance with "False" for the second ctor argument. It specifies if data is appended (True means Append, False means overwrite or create a new file)
Dim fw As New System.IO.StreamWriter(Server.MapPath("MyData/" & strFname), False)
-- Teemu Keiski ASP.NET MVP, AspInsider Finland, EU http://blogs.aspadvice.com/joteke
"mosscliffe" <pa***********@googlemail.com> wrote in message news:11**********************@c74g2000cwc.googlegr oups.com...I have a simple form with a multiline Textbox.
I load the textbox with the contents of a text file.
I make changes to the textbox, then I attempt to OVERWRITE the original file.
I have tried opening with FilMode.Create, FileMode.Truncate but they bothh APPEND to the file.
What is the correct syntax for Overwriting - Thanks for any help
My Code is as follows:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strFname As String = DropDownList1.SelectedItem.Text lblDebug.Text += "LoadButton: " & DropDownList1.SelectedItem.Text & "<BR />" Dim fw As New System.IO.StreamReader(Server.MapPath("MyData/" & strFname), True) TextBox1.Text = fw.ReadToEnd() fw.Close() fw.Dispose()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Dim strFname As String = DropDownList1.SelectedItem.Text lblDebug.Text += "UpdateButton: " & DropDownList1.SelectedItem.Text & "<BR />" Dim fw As New System.IO.StreamWriter(Server.MapPath("MyData/" & strFname), System.IO.FileMode.Create) fw.Write(TextBox1.Text) fw.Close() fw.Dispose()
End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Don |
last post by:
Hi all,
With regards to the following, how do I append the datetimestamp to
the filenames in the form? The files are processed using the PHP
script that follows below.
Thanks in advance,...
|
by: Robert |
last post by:
Hi,
Is it me or is the recv() function not erasing but only overwriting the last
data it supplied?
example:
when i first send:
"login robert test"
|
by: Mike P |
last post by:
Does anybody have a simple example of appending text to a text file?
Cheers,
Mike
*** Sent via Developersdex http://www.developersdex.com ***
|
by: amitp |
last post by:
Can anyone help me out in this? I want to append multiple RTF file into one RTF file. I tried using 'streamwriter', the resulting file size becomes big and when i open it, it is the original i.e the...
|
by: Vivek |
last post by:
Hi,
Iam using the db2load API to write data to a table. I see that by
default the load process creates/overwrites the msgfile. Is there a way
to change this behaviour so that messages are...
|
by: Frank |
last post by:
Hi,
Let's say I have a file named myFile.xml
Within that file I have blocks of data which I'd like to add at different
times during the day.
e.g.
<LogEntry>
|
by: ukgrl_yr79 |
last post by:
hi
fairly new to vb.net . I have created a filesystem where a manager
and co workers hve limted access.
the manager can read members files. i have used streamreader to get
the details from...
|
by: =?Utf-8?B?RHVja3dvbg==?= |
last post by:
Hello,
My code is suppose to write to an existing file. But after my C# code
appends the file, the previous text loses all the endline characters,
becoming one long line. How can I retain the...
|
by: ofuuzo1 |
last post by:
Hi,
Is there anyway I can append a new element to an existing xml without
first loading the existing file into a variable, adding the new
element into the variable and saving it by overwriting the...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |