473,767 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Append Text(Chr(167) )

-------

or

-------

TextBox1.Append Text("§")

-------

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|a ll files (*.*)|*.*"

If SaveFileDialog1 .ShowDialog() = DialogResult.OK Then

file_name = SaveFileDialog1 .FileName

Dim file As System.IO.FileS tream

file = System.IO.File. Create(file_nam e)

file.Close()

Dim fw As New StreamWriter(fi le_name)

fw.Write(TextBo x1.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 1185
"poldoj" <po********@gma il.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.En coding'.

--
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\StringTe xt.txt")
Dim stw As New StreamWriter("C :\Test2\StringT ext.txt")
stw.WriteLine(" 123âäfabc")
stw.Close()
Dim Str As New StreamReader("C :\Test2\StringT ext.txt")
Dim arrInput As Byte() = _
System.Text.Enc oding.GetEncodi ng(437).GetByte s(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(fi le_name, True,
System.Text.Enc oding.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
9567
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 encrypt text before writing to a database and decrypt it when reading it back. I figured I'd use a MemoryStream that I can either store as a blob or convert to a string and store as a varchar. Anyway, I can't get the CryptoStream to write to the...
1
1343
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 interface system. I am just working with plain text now but I was wondering what differences I would have to make to save between .txt, .rtf, or even .doc if possible. Thanks for any help you could give or examples you could point me to . Thanks again.
2
6860
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 replace just one item. I know I can get the entire array, then save the whole thing (with a for loop and if statements so that the changed data will be saved), but it seems like a lot of unnecessary reading and writing. Is there a way to directly save...
21
2968
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 updated this system and changed the pages that are saved to the server as aspx - everything works fine and pages can be served - but Its not impossible for a single client to request 100 plus pages in one session - as each page is requested it is...
16
2206
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
1
1138
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 using msgboxes). Any idea why it wouldnt be writing anything? Do Until (objFacilitySht.Cells(row, cboAPName.Text).Value = "") Dim fsStream As New FileStream(txtSaveto.Text & "\" & objFacilitySht.Cells(row, cboAPName.Text).Value & ".txt",...
10
19176
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 am passing to it. Everything works fine on IE 6. Here's a couple samples of what I am doing: // using GET url = 'http://www.myserver.com/cgi-bin/funct?key1=value1&key2=value2'
2
3276
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 and arrays of pointers to them. I have gotten the program to compile with gcc on WinXP. If the file i read doesnt have alot of records, it runs thru. But once i add more, it dies. In this program i have 4 files setup to read. The
3
7078
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; NewLineIdr = 0x0000; I need it to use it in my saving procedure because I need to create tabullary text file. But my effort usually results in one or two small
0
9571
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10009
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8835
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.