473,385 Members | 1,341 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.

Problems with writing a text file (again)

First I would thank you all for the replies at my previous post. Say sorry
for my poor english also. I have found where my problem came from. I am
writing a string to a text box and write the content of that textbox to a
file. All is just fine until I try to pass this character to the textbox:

exemple:

------

TextBox1.AppendText(Chr(167) )

-------

or

-------

TextBox1.AppendText("§")

-------

that is the same thing. Then I have this code in the click button event (the
save button):

-------

Try

Dim file_name As String

SaveFileDialog1.Filter = "text files (*.txt)|*.txt|all files (*.*)|*.*"

If SaveFileDialog1.ShowDialog() = DialogResult.OK Then

file_name = SaveFileDialog1.FileName

Dim file As System.IO.FileStream

file = System.IO.File.Create(file_name)

file.Close()

Dim fw As New StreamWriter(file_name)

fw.Write(TextBox1.Text)

fw.Close()

End If

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

------------

My text file is generated without problems, if I try to open it with notepad
just display my character "§"

But if I open this file with wordpad it show "§". When I try to read this
files from another applications I get this unwanted  character. I don't
know how to pass this "§" in the right way for display only the §.

Thanks.
Nov 21 '05 #1
3 1165
"poldoj" <po********@gmail.com> schrieb:
My text file is generated without problems, if I try to open it with
notepad just display my character "§"

But if I open this file with wordpad it show "§". When I try to read this
files from another applications I get this unwanted  character. I don't
know how to pass this "§" in the right way for display only the §.


You may want to use a different encoding when writing the file. At least
one overload of the 'StreamWriter' takes a 'System.Text.Encoding'.

--
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
Poldoj,

I have had this problem as well. It was when I had set for some testing my
computer to another country which was using another codeset than I thought I
was using, not any encoding did help me than.

After setting it back all problems where gone.

Maybe you can check that if you did the same.

And then when that is not enough you can look which codeset you are using
and than something as

\\\
Public Shared Sub main()
If File.Exists("C:\Test2\Text.txt") Then _
File.Delete("C:\Test2\StringText.txt")
Dim stw As New StreamWriter("C:\Test2\StringText.txt")
stw.WriteLine("123âäfabc")
stw.Close()
Dim Str As New StreamReader("C:\Test2\StringText.txt")
Dim arrInput As Byte() = _
System.Text.Encoding.GetEncoding(437).GetBytes(Str .ReadToEnd)
Str.Close()
End Sub
////

Where 437 is one of the codetables that is used on my computer (You can as
well try 1252 (latin))

Cor
Nov 21 '05 #3
I finally found the solution:
----------------------
Dim SwBuffer = New StreamWriter(file_name, True,
System.Text.Encoding.Default, 512)

SwBuffer.Write(TextBox1.Text)

SwBuffer.Flush()

SwBuffer.Close()

-----------------------------

Thank all for help and patience :)
Nov 21 '05 #4

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

Similar topics

7
by: Stingray | last post by:
Are there any know problems with using a MemoryStream as a backing store for a CryptoStream? I'm trying to simply encrypt and decrypt text in memory. I'd like to create some simple methods to...
1
by: David Johnston | last post by:
I am converting to the .NET platform and I am starting with C#. Just for exercise I'm writing a text editor and I am having some problems with saving files. I am using a single document...
2
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
16
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
1
by: chauc3r | last post by:
I'm having problems writing to a text file. Basically it refuses to write anything. The file is created. At the appropiate times it goes into the correct if statements (I have verified this...
10
by: Danny | last post by:
Hi all, I am having some odd problems with AJAX on Firefox (1.5). When I use GET as the request method everything works ok, but when I do a POST the remote function doesn't get the parameters I...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
3
by: MIUSS | last post by:
Hello everyone! I got a problem with creating new line... I tried this: lstrcpy(NewLineIdr, TEXT("\r\n")); I already tried this: NewLineIdr = 0x000D; NewLineIdr = 0x000A;...
0
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...
0
isladogs
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...

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.