Wednesday, April 27, 2016 | By: nika perales

Opening notepad from C# app

In this post i'll show you how to open notepad windows application from our C# project. This is useful when you want to display a particular text file to a user.
Private void RunNotepad()
{
 Process Notepadprocess  = new Process();
 Notepadprocess.StartInfo = new ProcessStartInfo("notepad.exe", "E:\\New.txt");
 Notepadprocess.Start();
}
 

C# random filename generator

Import namespace
using System.IO;
Code
string path = @"C:\Folder\file.txt";

Console.WriteLine(path);
Console.WriteLine();

Console.WriteLine("Directory name: {0}", Path.GetDirectoryName(path));
Console.WriteLine("File name: {0}", Path.GetFileName(path));
Console.WriteLine("File name without extension: {0}", Path.GetFileNameWithoutExtension(path));
Console.WriteLine("File extension: {0}", Path.GetExtension(path));

Sample output

Directory name: C:\Folder
File name: file.txt
File name without extension: file
File extension: .txt

Read available disk space

Does your program need to get the available disk space on your computer. Here's the .net code
Import namespace
using System.IO;

Code
using System.IO;
DriveInfo drive = new DriveInfo(@"C:\");
long space = drive.AvailableFreeSpace;