Click here to Skip to main content
15,888,280 members
Home / Discussions / C#
   

C#

 
GeneralWideChar Pin
yyf17-Sep-04 3:14
yyf17-Sep-04 3:14 
GeneralRe: WideChar Pin
Heath Stewart17-Sep-04 6:33
protectorHeath Stewart17-Sep-04 6:33 
GeneralFilefield postback woes Pin
Vodstok17-Sep-04 3:08
Vodstok17-Sep-04 3:08 
GeneralRe: Filefield postback woes Pin
sreejith ss nair17-Sep-04 3:40
sreejith ss nair17-Sep-04 3:40 
GeneralRe: Filefield postback woes Pin
Vodstok17-Sep-04 4:36
Vodstok17-Sep-04 4:36 
GeneralStream writing html Pin
Mikke_x17-Sep-04 2:50
Mikke_x17-Sep-04 2:50 
GeneralRe: Stream writing html Pin
Steven Campbell17-Sep-04 4:33
Steven Campbell17-Sep-04 4:33 
GeneralRe: Stream writing html Pin
Heath Stewart17-Sep-04 6:53
protectorHeath Stewart17-Sep-04 6:53 
Steven's right, but what you need to do is actually quite easy.

Wrap your FileStream (or whatever Stream derivative you're using) in a StreamReader or StreamWriter, which makes reading and writing text much easier. You can specify the encoding (like Encoding.Unicode, since you're probably dealing with Unicode characters on the 'net, or UTF8 which is most common (a multi-byte character set, or MBCS)) and with the <code>StreamReader you can set a parameter in the constructor that attempts to detect the encoding by detecting a byte-order mark (BOM).

For example:
using (FileStream file = File.Open("somefile.html", FileMode.Open))
{
  string line = null;
  using (StreamReader reader = new StreamReader(file, Encoding.UTF8, true))
  {
    // It's bad to use reader.ReadToEnd - you might not have enough memory
    line = reader.ReadLine();
    // Do something with the 'line'
  }
}
The using blocks make sure the streams are closed (i.e., the native file handles are released - very important or your performance is hampered, or - worse yet - you have memory leaks).

You should really read about the Encoding class in the .NET Framework SDK. You could still read and write bytes but you must understand that ANSI is a single-byte character set, and may use different code pages. ASCII characters use only 7 bits in the byte (the first 128 values). The last 128 values can be different depending on the codepage (local characters, or defined for particular systems). UTF8 can handle ASCII characters, but those latter characters actually tell the decoder to use 2 bytes to read the character, thus supporting Unicode as well. This is a great encoding to use on legacy systems, especially if you're not sure what a text file will contain (although a legacy decore might have problems). Unicode comes in many flavors, and you can read more on the web if you try a google search or click "Search comments" above for previous discussions we've had about this.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
GeneralRe: Stream writing html Pin
Mikke_x17-Sep-04 7:14
Mikke_x17-Sep-04 7:14 
Generalposting data to another url using webclient Pin
Abraham Durairaj17-Sep-04 0:31
Abraham Durairaj17-Sep-04 0:31 
GeneralMaskEdit Pin
jzb17-Sep-04 0:09
jzb17-Sep-04 0:09 
GeneralRe: MaskEdit Pin
Heath Stewart17-Sep-04 6:37
protectorHeath Stewart17-Sep-04 6:37 
GeneralGraphical programming Pin
Member 62427317-Sep-04 0:06
Member 62427317-Sep-04 0:06 
GeneralRe: Graphical programming Pin
Colin Angus Mackay17-Sep-04 1:10
Colin Angus Mackay17-Sep-04 1:10 
Generalcustom progressbar, problem updating it. Pin
misterbear16-Sep-04 23:50
misterbear16-Sep-04 23:50 
GeneralRe: custom progressbar, problem updating it. Pin
Stefan Troschuetz17-Sep-04 2:47
Stefan Troschuetz17-Sep-04 2:47 
GeneralRe: custom progressbar, problem updating it. Pin
Tim Kohler17-Sep-04 9:49
Tim Kohler17-Sep-04 9:49 
Generalcorrel function for c# Pin
tradingsharp16-Sep-04 22:56
tradingsharp16-Sep-04 22:56 
GeneralRe: correl function for c# Pin
leppie16-Sep-04 23:46
leppie16-Sep-04 23:46 
GeneralReg. Posting data to other url Pin
Abraham Durairaj16-Sep-04 18:50
Abraham Durairaj16-Sep-04 18:50 
QuestionHow can I add , update , delete a row Pin
skywen16-Sep-04 16:51
skywen16-Sep-04 16:51 
AnswerRe: How can I add , update , delete a row Pin
sreejith ss nair16-Sep-04 23:59
sreejith ss nair16-Sep-04 23:59 
AnswerRe: How can I add , update , delete a row Pin
Kodanda Pani17-Sep-04 21:06
Kodanda Pani17-Sep-04 21:06 
QuestionHow do i force a control to only exist in the component tray? Pin
FocusedWolf16-Sep-04 15:59
FocusedWolf16-Sep-04 15:59 
GeneralServer application Pin
qigong516-Sep-04 13:37
qigong516-Sep-04 13:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.