Get application version via runtime code:
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
//include this //for registry read write using Microsoft.Win32; public string ReadRegistryValue(string KeyName) { // Opening the registry key RegistryKey key = Registry.LocalMachine; // Open a subKey as read-only RegistryKey subkey = key.OpenSubKey(@"SOFTWARE\SKYPE\PHONE"); // If the RegistrySubKey doesn't exist -> (null) if (subkey == null) { return null; } else { try { //return value return (string)subkey.GetValue(KeyName); } catch (Exception e) { //display error MessageBox.Show("Reading registry Exception " + e.Message.ToString()); return null; } } } //method usage MessageBox.Show(ReadRegistryValue("SkypePath"));Additional Reading at :
//include this using System.IO; public void CreateFolder(string FolderPath) { // Specify the directories you want to manipulate. DirectoryInfo di = new DirectoryInfo(FolderPath); try { //check folder already exists. if (di.Exists) { MessageBox.Show("Folder already exists."); } else { //create folder di.Create(); } } catch (Exception e) { MessageBox.Show(e.ToString()); } } public void DeleteFolder(string FolderPath) { // Specify the directories you want to manipulate. DirectoryInfo di = new DirectoryInfo(FolderPath); try { //check folder exists. if (di.Exists) { //delete all including sub folder di.Delete(true); } } catch (Exception e) { MessageBox.Show(e.ToString()); } } public void CopyAll(DirectoryInfo source, DirectoryInfo target) { if (source.FullName.ToLower() == target.FullName.ToLower()) { return; } // check target folder exists if (Directory.Exists(target.FullName) == false) { //create target target folder Directory.CreateDirectory(target.FullName); } //copy each file to target folder foreach (FileInfo fi in source.GetFiles()) { fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true); } //copy each sub folder to target folder foreach (DirectoryInfo diSourceSubDir in source.GetDirectories()) { DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name); //copy all file from subfolder to target subfolder CopyAll(diSourceSubDir, nextTargetSubDir); } } public void MoveAll(DirectoryInfo source, DirectoryInfo target) { try { //check source folder exist if(source.Exists) //check destination not exist if(!target.Exists) source.MoveTo(target.ToString()); } catch (IOException e) { MessageBox.Show(e.Message); } } public void RenameTo(DirectoryInfo di, string NewName) { if (di == null) { MessageBox.Show("Directory info to rename cannot be null"); } if (string.IsNullOrWhiteSpace(NewName)) { MessageBox.Show("New name cannot be null or blank"); } di.MoveTo(Path.Combine(di.Parent.FullName, NewName)); } //method usage CreateFolder(@"C:\NewFolder"); DeleteFolder(@"C:\FolderToDelete"); DirectoryInfo Source = new DirectoryInfo(@"C:\SourceFolder"); DirectoryInfo Target = new DirectoryInfo(@"C:\TargetFolder"); CopyAll(Source, Target); MoveAll(Source, Target); RenameTo(Source, "NewName");Additional Reading :
//include this using System.IO; //set directory to scan var dirInfo = new DirectoryInfo(@"C:\FolderName"); //checking if folder exists if (dirInfo.Exists) { //*.* = get all file name FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.TopDirectoryOnly); foreach (FileInfo file in files) { //example to list the file name using messagebox MessageBox.Show(file.ToString()); } }Additional Reading at :
//include this using System.Diagnostics; //example String Text = "Text Something"; Debug.WriteLine(Text);