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

StreamWriter, StringWriter and encoding...

Hello,

i have a big problem with my email component, because each time i write the
generated message directly to the spooler, the streamwriter will write in
Unicode.

The file starts with a FF FE and is double byte.

This is a problem because when a mail server like QMAIL receive the message,
will reject for malformed LF.

Infact, the file is Unicode and the normal CR/LF is (0D 00 0A 00) and QMAIL
reading 00 0A fails.

I tried everithing...

The code:

StringWriter SW = new StringWriter(new StringBuilder());
SW.WriteLine("x-sender: <" + this._From.Address + ">");
[...]
string message = SW.ToString();
using (StreamWriter sw = new StreamWriter(filename,true,Encoding.ASCII))
{
sw.Write(message);
}

Please help,
Regards
Stefano
Nov 16 '05 #1
6 31051
kinekine@digita wrote:
Hello,

i have a big problem with my email component, because each time i
write the generated message directly to the spooler, the streamwriter
will write in Unicode.

The file starts with a FF FE and is double byte.

This is a problem because when a mail server like QMAIL receive the
message, will reject for malformed LF.

Infact, the file is Unicode and the normal CR/LF is (0D 00 0A 00) and
QMAIL reading 00 0A fails.

I tried everithing...

The code:

StringWriter SW = new StringWriter(new StringBuilder());
SW.WriteLine("x-sender: <" + this._From.Address + ">");
[...]
string message = SW.ToString();
using (StreamWriter sw = new
StreamWriter(filename,true,Encoding.ASCII)) {
sw.Write(message);
}


Now I'm confused. This StreamWriter writes ASCII, which will drop any
non-7-bit character...

--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 16 '05 #2

Try

new StreamWriter(filename,Encoding.Default)

"kinekine@digita" <ki************@discussions.microsoft.com> wrote in
message news:3B**********************************@microsof t.com...
Hello,

i have a big problem with my email component, because each time i write
the
generated message directly to the spooler, the streamwriter will write in
Unicode.

The file starts with a FF FE and is double byte.

This is a problem because when a mail server like QMAIL receive the
message,
will reject for malformed LF.

Infact, the file is Unicode and the normal CR/LF is (0D 00 0A 00) and
QMAIL
reading 00 0A fails.

I tried everithing...

The code:

StringWriter SW = new StringWriter(new StringBuilder());
SW.WriteLine("x-sender: <" + this._From.Address + ">");
[...]
string message = SW.ToString();
using (StreamWriter sw = new StreamWriter(filename,true,Encoding.ASCII))
{
sw.Write(message);
}

Please help,
Regards
Stefano

Nov 16 '05 #3
Already tried, with o without an encoding specified, will always save to
Unicode.

please note that the content is fully in ascii range.

Exists a function or a trick to save in single byte?

Stefano

"Michael S" wrote:

Try

new StreamWriter(filename,Encoding.Default)

"kinekine@digita" <ki************@discussions.microsoft.com> wrote in
message news:3B**********************************@microsof t.com...
Hello,

i have a big problem with my email component, because each time i write
the


Nov 16 '05 #4
kinekine@digita <ki************@discussions.microsoft.com> wrote:
Already tried, with o without an encoding specified, will always save to
Unicode.


In that case your code is wrong, or you're misdiagnosing the problem.
With no encoding specified, it should be using UTF-8.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Hello Jon,

i can't post the whole class to the newsgroup because is very big, and
nothing can be stripped out or the result will be different.

I will send you the class privately, please take a look.

Regards,

Stefano

"Jon Skeet [C# MVP]" wrote:
kinekine@digita <ki************@discussions.microsoft.com> wrote:
Already tried, with o without an encoding specified, will always save to
Unicode.


In that case your code is wrong, or you're misdiagnosing the problem.
With no encoding specified, it should be using UTF-8.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #6
kinekine@digita <ki************@discussions.microsoft.com> wrote:
i can't post the whole class to the newsgroup because is very big, and
nothing can be stripped out or the result will be different.
I find that hard to believe, I'm afraid.
I will send you the class privately, please take a look.


I'll have a brief look, but if it's that big, it will probably take
longer than I've got time spare. As the person who understands the code
best, you're in the best position to cut it down (or start from scratch
to build up a short but complete program).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7

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

Similar topics

2
by: Chris Lacey | last post by:
Is anyone aware why the following code (intended to write XML into a memory-based XmlTextWriter, and return the complete document as a string) produces badly formed XML due to the resultant string...
4
by: Majed | last post by:
Hi , all I'm trying to write unicode to a file for another app (not developed with vs2003) to read it. I used StreamWriter with unicode encoding.but I was surprised that the streamwriter adds FFFE...
3
by: Lou | last post by:
How do i create a unicode stream writer? Below is my code but its ascii... private FileStream myStream; //Create the Stream Writer, this is ascii sw=new StreamWriter(myStream); ...
5
by: Waldy | last post by:
Hi there, how do you set the encoding format of an XML string? When I was outputting the XML to a file you can specify the encoding format like so: XmlTextWriter myWriter; myWriter = new...
4
by: ASP Yaboh | last post by:
I am using StreamWriter's .Writeline() method to create a simple text file. I found that ASCII characters 255 & 254 are being inserted as the first two characters of the file which causes a...
10
by: Oscar Thornell | last post by:
Hi, I generate and temporary saves a text file to disk. Later I upload this file to Microsoft MapPoint (not so important). The file needs to be in UTF-8 encoding and I explicitly use the...
1
by: Anthony Nystrom | last post by:
I am trying to pass a text stream from streamwriter class to a richtextbox, or textbox doesn't matter which one. I have the file write version working fine such as: x.streamwriter =...
1
by: Brad Wood | last post by:
I am testing a web service that returns an XML doc as a string. I went through troubles when developing it whereby the saved output of the service would not display in Internet Explorer due to...
4
by: Mads Westen | last post by:
Hi, I'm parsing some XML files, and converting them to CSV. I got x number of XML files in a directory, these files do I need to be converted and written to the same CSV file. My problem is...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.