Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
1. read all the contents of a File
string output = File.ReadAllText(<FilePath>);
2. Write contents to a File
File.WriteAllText(<FilePath>,Encoding);
3. Convert String to Byte Array
byte[] buf = System.Text.Encoding.<Encoding>.GetBytes(string);
4. Convert Byte to String
string output = System.Text.Encoding.<Encoding>.GetString(byte[]);
Comments
Anonymous
December 19, 2007
PingBack from http://msdnrss.thecoderblogs.com/2007/12/20/code-snippets-for-common-operations/Anonymous
May 07, 2008
- Copying one stream to another FileStream _fStream = new FileStream(@"<FilePath>",FileMode.Open); MemoryStream _stream = new MemoryStream(); byte[] buffer = new byte[1024]; int nrBytesWritten = _fStream.Read(buffer, 0, 1024); while (nrBytesWritten > 0) { _stream.Write(buffer, 0, nrBytesWritten); nrBytesWritten = _fStream.Read(buffer, 0, 1024); }