Writing to the console

Write strings to the console System.Diagnostics.Debug.WriteLine("My Value: " + Convert.ToString(MyVariable)); or using System.Diagnostics; Debug.WriteLine("My Value: " + Convert.ToString(MyVariable)); Display a byte array as a string System.Diagnostics.Debug.WriteLine("CommsByteArray: " + Encoding.UTF8.GetString(CommsByteArray));  

Read More

Special Directories

Location To Store Application Data private const string MY_FILE_DIRECTORY_TO_USE Environment::GetFolderPath(Environment::SpecialFolder::ApplicationData) + "\\" + Application::CompanyName + "\\" + Application::ProductName + "\\" Windows 7 path from using the above: C:\Users\MyUserName\AppData\Roaming\Company Name\App Name N.B. SpecialFolder::CommonApplicationData is not the same as ApplicationData.  Non-Admin users and applications running as a non admin user do not have permission to write to the CommonApplicationData […]

Read More

XmlDocument

Editing a xml file XmlDoc = new XmlDocument(); XmlDoc.Load(filename); //Remove the xml file header foreach (XmlNode node in XmlDoc) { if (node.NodeType == XmlNodeType.XmlDeclaration) { XmlDoc.RemoveChild(node); } }  

Read More

.MemoryStream General

Read file into Memory Stream MemoryStream SourceXmlMemoryStream = new MemoryStream(File.ReadAllBytes(filename)); Write File From Memory Stream FileStream file = new FileStream(filename, FileMode.Create, FileAccess.Write); //Overwrite the existing file OutputXmlMemoryStream.WriteTo(file); file.Close(); OutputXmlMemoryStream.Close(); Seek SourceXmlMemoryStream.Seek(0, SeekOrigin.Begin); or SourceXmlMemoryStream.Position = 0 Close Memory Stream SourceXmlMemoryStream.Dispose(); Write MemoryStream To File (Overwrite if alreads exists) MemoryStream1.Position = 0; System.IO.File.WriteAllBytes("C:\\_Downloaded\\test1.bin", MemoryStream1.ToArray()); Convert Memory […]

Read More

Converting Strings

HTML Encode / Decode strings string MyString = “<hello>”; MyString = WebUtility.HtmlEncode(MyString); string MyString = “&lt;hello&gt;”; MyString = WebUtility.HtmlDecode(MyString);  

Read More

Working With Strings

Read individual characters from a string Treat the string as an array string MyString = “abcd”; char MyChar = MyString[2]; Get Characters Between Markers Within String string sTemp = responseStr; string StartAfterChars; string EndBeforeChars; int Start; int Length; string FoundString; StartAfterChars = “<requestID>”; EndBeforeChars = “</requestID>”; Start = sTemp.IndexOf(StartAfterChars) + StartAfterChars.Length; Length = sTemp.IndexOf(EndBeforeChars) – […]

Read More

.Strings General

string or String string is an alias in C# for System.String.So technically there is no difference (it’s like int and System.Int32). Best practice: Use string any time you’re referring to an object. Use String if you need to refer specifically to the class. Multi Line Strings Use the ‘@’ character before the string to create […]

Read More

Create A GUID

https://en.wikipedia.org/wiki/Globally_unique_identifier string NewGuid = Guid.NewGuid().ToString();  

Read More

.Useful Things

Debug Mode Only Compiler Check Close Application Restart Application / Soft Reset You can simply close the app and then the OS will immediately restart it 

Read More

UTC

Converting a DateTime to Universal Time Format allows you to avoid local date time format issues when passing DateTime values between systems. Then just use Convert.ToDateTime to convert it back. Get Current Time In UTC Use .UtcNow instead of .Now Simpler: Convert UTC To Local Format

Read More