Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2007

Tip: Looking for answers? Try searching our database.

Encoding Text für writing a textfile

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martin Fischer - 07 Dec 2007 21:24 GMT
Hi everybody,

i have a problem with teh StreamWriter Object. I want to force the Stream to
write an ANSI-text. For reading from an filestream i can define the type of
ASCI by setting
System.Text.Encoding.Default.

What about Wrting Textdate ? The result seems to be UTF7 -Charset, but no
real ANSI.

Any hint for me ?

Martin
Peter Duniho - 07 Dec 2007 21:47 GMT
> Hi everybody,
>
[quoted text clipped - 4 lines]
> ASCI by setting
> System.Text.Encoding.Default.

What "type of ASCII"?  There's only one ASCII.  How do you set  
System.Text.Encoding.Default, given that it's a read-only property?

As far as the StreamWriter goes, you can specify an encoding via the  
constructor when you instantiate the StreamWriter.

Pete
RobertK - 07 Dec 2007 22:29 GMT
Do you mean you want the file written in plain ASCII?

This appears to produce a simple ASCII text file:

FileStream FS = new FileStream("d:\\myfile.txt",FileMode.OpenOrCreate);
StreamWriter SW = new StreamWriter(FS, Encoding.ASCII);
Martin Fischer - 08 Dec 2007 06:45 GMT
Thanks a lot. Thats what i ve been searching for ...

I have been trying to create a StreamWriter-Object without creating a
previos filestram, and in this structure i didnt find a way to specify the
Encodeng ....

Wish you a nice weekend.

Martin

> Do you mean you want the file written in plain ASCII?
>
> This appears to produce a simple ASCII text file:
>
> FileStream FS = new FileStream("d:\\myfile.txt",FileMode.OpenOrCreate);
> StreamWriter SW = new StreamWriter(FS, Encoding.ASCII);
Peter Duniho - 08 Dec 2007 07:41 GMT
> I have been trying to create a StreamWriter-Object without creating a
> previos filestram, and in this structure i didnt find a way to specify  
> the
> Encodeng ....

Why there's no StreamWriter(String, Encoding) overload, I don't know.  But  
there are other overloads for the StreamWriter constructor that take a  
file name and an encoding.  For example:

http://msdn2.microsoft.com/en-us/library/f5f5x7kt.aspx

Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.