Csharp/C Sharp/File Stream/Path
Path.GetTempFileName
using System;
using System.IO;
class MainClass {
static void Main() {
string tempFile = Path.GetTempFileName();
Console.WriteLine("Using " + tempFile);
using (FileStream fs = new FileStream(tempFile, FileMode.Open)) {
// (Write some data.)
}
// Now delete the file.
File.Delete(tempFile);
}
}
Paths in C#
/*
s = new FileStream("C:\\temp\\Goo.txt", FileMode.Create);
or use forward (Unix-style) slashes:
s = new FileStream("C:/temp/Goo.txt", FileMode.Create);
or use the at sign (@), which is a control-character suppressor:
s = new FileStream(@"C:\temp\Goo.txt", FileMode.Create);
*/
Use static methods in Path
using System;
using System.Diagnostics;
using System.IO;
class TestPathApp {
static void Main(string[] args) {
Process p = Process.GetCurrentProcess();
ProcessModule pm = p.MainModule;
string s = pm.ModuleName;
Console.WriteLine(Path.GetFullPath(s));
Console.WriteLine(Path.GetFileName(s));
Console.WriteLine(Path.GetFileNameWithoutExtension(s));
Console.WriteLine(Path.GetDirectoryName(Directory.GetCurrentDirectory()));
Console.WriteLine(Path.GetPathRoot(Directory.GetCurrentDirectory()));
Console.WriteLine(Path.GetTempPath());
Console.WriteLine(Path.GetTempFileName());
}
}