473,586 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ne w StringBuilder() );
SW.WriteLine("x-sender: <" + this._From.Addr ess + ">");
[...]
string message = SW.ToString();
using (StreamWriter sw = new StreamWriter(fi lename,true,Enc oding.ASCII))
{
sw.Write(messag e);
}

Please help,
Regards
Stefano
Nov 16 '05 #1
6 31072
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(ne w StringBuilder() );
SW.WriteLine("x-sender: <" + this._From.Addr ess + ">");
[...]
string message = SW.ToString();
using (StreamWriter sw = new
StreamWriter(fi lename,true,Enc oding.ASCII)) {
sw.Write(messag e);
}


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

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

Try

new StreamWriter(fi lename,Encoding .Default)

"kinekine@digit a" <ki************ @discussions.mi crosoft.com> wrote in
message news:3B******** *************** ***********@mic rosoft.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(ne w StringBuilder() );
SW.WriteLine("x-sender: <" + this._From.Addr ess + ">");
[...]
string message = SW.ToString();
using (StreamWriter sw = new StreamWriter(fi lename,true,Enc oding.ASCII))
{
sw.Write(messag e);
}

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(fi lename,Encoding .Default)

"kinekine@digit a" <ki************ @discussions.mi crosoft.com> wrote in
message news:3B******** *************** ***********@mic rosoft.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.mi crosoft.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.co m>
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.mi crosoft.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #6
kinekine@digita <ki************ @discussions.mi crosoft.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.co m>
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
2448
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 always commencing with a question mark string xmlRequestString; MemoryStream memoryStream = new MemoryStream(); XmlTextWriter xmlTextWriter =...
4
2449
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 to the start of the file,which stopes the other app from reading it!! any idea how to stope it frome doing that,do I have to use another class...
3
12947
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); sw.WriteLine(Buffer + "\n");
5
5244
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 XmlTextWriter(myXMLFile, System.Text.Encoding.UTF8);
4
7701
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 3rd-party users' parser to fail. It is not being inserted by my data as the first line starts with "LOGIN: ", i.e. hard-coded. Has anyone else...
10
4634
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 "Encoding.UTF8" in the constructor like this: StreamWriter writer = new StreamWriter(file, Encoding.UTF8); When I do this the StreamWriter inserts an...
1
1634
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 = System.IO.File.CreateText("C:\text.txt") Anyway to write to a textbox or rtf rather than file... ? Thanks in advance...
1
1479
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 encoding confusion. I finally settled on setting responseEncoding in my web.config file to "utf-16" and saving the output of the service encoded as...
4
14362
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 that my csv file only contains the data from the last XML file parsed... I got the following code for creating of my StreamWriter: public...
0
8204
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. ...
1
7965
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...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3838
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...
0
3869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1184
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...

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.