@manhnguyenv

Welcome to my blog!

CSharp Common Functions

May 3, 2018 10:27

CSharp Common Functions (edit)

Write text to file

System.IO.File.WriteAllText(@"c:\temp\testfile.txt", "Hello World\r\nline2\r\nline3", System.Text.Encoding.UTF8);

https://www.arclab.com/en/kb/csharp/read-write-text-file-ansi-utf8-unicode.html

Copy file

System.IO.File.Copy(@"c:\temp\testfile1.txt", @"c:\temp\testfile2.txt", true);

Get string to byte array

string data = GetData(); // get the data from somewhere.  

byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);  

System.IO.File.WriteAllBytes("location", bytes);

 

Categories

Recent posts