-
-
Save Epic-Santiago/b842d06370cb56d2b1af43ae1f45f5e8 to your computer and use it in GitHub Desktop.
Paths in custom code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Before | |
var oldPath = @"C:\MyFolder\Test.txt"; | |
System.IO.Directory.CreateDirectory(oldPath); | |
System.IO.Directory.Delete(oldPath); | |
System.IO.Directory.Delete(oldPath, recursive: true); | |
System.IO.Directory.Exists(oldPath); | |
System.IO.Directory.GetDirectories(oldPath); | |
System.IO.Directory.GetDirectories(oldPath, "*abc*"); | |
System.IO.Directory.GetDirectories(oldPath, "*abc*", System.IO.SearchOption.AllDirectories); | |
System.IO.Directory.GetFiles(oldPath); | |
System.IO.Directory.GetFiles(oldPath, "New*"); | |
System.IO.Directory.GetFiles(oldPath, "New*", System.IO.SearchOption.AllDirectories); | |
System.IO.File.AppendAllLines(oldPath, new[] { "Line1", "Line2" }); | |
System.IO.File.AppendAllLines(oldPath, new[] { "Line1", "Line2" }, System.Text.Encoding.Unicode); | |
System.IO.File.AppendAllText(oldPath, "Some text!"); | |
System.IO.File.AppendAllText(oldPath, "Some text!", System.Text.Encoding.Unicode); | |
System.IO.File.Copy(oldPath, oldPath2); | |
System.IO.File.Copy(oldPath, oldPath2, overwrite: true); | |
System.IO.File.Create(oldPath); | |
System.IO.File.CreateText(oldPath); | |
System.IO.File.Delete(oldPath); | |
System.IO.File.Exists(oldPath); | |
System.IO.File.Move(oldPath, oldPath2); | |
System.IO.File.Move(oldPath, oldPath2, overwrite: true); | |
System.IO.File.Open(oldPath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); | |
System.IO.File.OpenRead(oldPath); | |
System.IO.File.OpenText(oldPath); | |
System.IO.File.OpenWrite(oldPath); | |
System.IO.File.ReadAllBytes(oldPath); | |
System.IO.File.ReadAllText(oldPath, System.Text.Encoding.UTF8); | |
System.IO.File.ReadAllLines(oldPath, System.Text.Encoding.UTF8); | |
System.IO.File.WriteAllBytes(oldPath, new[] { (byte)'a', (byte)'b', (byte)'c' }); | |
System.IO.File.WriteAllLines(oldPath, new[] { "Line1", "Line2" }); | |
System.IO.File.WriteAllLines(oldPath, new[] { "Line1", "Line2" }, System.Text.Encoding.Unicode); | |
System.IO.File.WriteAllLines(oldPath, (IEnumerable<string>)(new[] { "Line1", "Line2" })); | |
System.IO.File.WriteAllLines(oldPath, (IEnumerable<string>)(new[] { "Line1", "Line2" }), System.Text.Encoding.Unicode); | |
System.IO.File.WriteAllText(oldPath, "Testing"); | |
System.IO.File.WriteAllText(oldPath, "Testing", System.Text.Encoding.Unicode); | |
var xml = new System.Xml.XmlDocument(); xml.Load(path); | |
// After | |
/* Choose from: | |
ServerFolder.UserData | |
ServerFolder.CompanyData | |
ServerFolder.FileShare | |
*/ | |
var newPath = new FilePath(ServerFolder.UserData, "Test.txt"); | |
Sandbox.IO.Directory.CreateDirectory(newPath); | |
Sandbox.IO.Directory.Delete(newPath); | |
Sandbox.IO.Directory.Delete(newPath, recursive: true); | |
Sandbox.IO.Directory.Exists(newPath); | |
Sandbox.IO.Directory.GetDirectories(newPath); | |
Sandbox.IO.Directory.GetDirectories(newPath, "*abc*"); | |
Sandbox.IO.Directory.GetDirectories(newPath, "*abc*", System.IO.SearchOption.AllDirectories); | |
Sandbox.IO.Directory.GetFiles(newPath); | |
Sandbox.IO.Directory.GetFiles(newPath, "New*"); | |
Sandbox.IO.Directory.GetFiles(newPath, "New*", System.IO.SearchOption.AllDirectories); | |
Sandbox.IO.File.AppendAllLines(newPath, new[] { "Line1", "Line2" }); | |
Sandbox.IO.File.AppendAllLines(newPath, new[] { "Line1", "Line2" }, System.Text.Encoding.Unicode); | |
Sandbox.IO.File.AppendAllText(newPath, "Some text!"); | |
Sandbox.IO.File.AppendAllText(newPath, "Some text!", System.Text.Encoding.Unicode); | |
Sandbox.IO.File.Copy(newPath, newPath2); | |
Sandbox.IO.File.Copy(newPath, newPath2, overwrite: true); | |
Sandbox.IO.File.Create(newPath); | |
Sandbox.IO.File.CreateText(newPath); | |
Sandbox.IO.File.Delete(newPath); | |
Sandbox.IO.File.Exists(newPath); | |
Sandbox.IO.File.Move(newPath, newPath2); | |
Sandbox.IO.File.Move(newPath, newPath2, overwrite: true); | |
Sandbox.IO.File.Open(newPath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); | |
Sandbox.IO.File.OpenRead(newPath); | |
Sandbox.IO.File.OpenText(newPath); | |
Sandbox.IO.File.OpenWrite(newPath); | |
Sandbox.IO.File.ReadAllBytes(newPath); | |
Sandbox.IO.File.ReadAllText(newPath, System.Text.Encoding.UTF8); | |
Sandbox.IO.File.ReadAllLines(newPath, System.Text.Encoding.UTF8); | |
Sandbox.IO.File.WriteAllBytes(newPath, new[] { (byte)'a', (byte)'b', (byte)'c' }); | |
Sandbox.IO.File.WriteAllLines(newPath, new[] { "Line1", "Line2" }); | |
Sandbox.IO.File.WriteAllLines(newPath, new[] { "Line1", "Line2" }, System.Text.Encoding.Unicode); | |
Sandbox.IO.File.WriteAllLines(newPath, (IEnumerable<string>)(new[] { "Line1", "Line2" })); | |
Sandbox.IO.File.WriteAllLines(newPath, (IEnumerable<string>)(new[] { "Line1", "Line2" }), System.Text.Encoding.Unicode); | |
Sandbox.IO.File.WriteAllText(newPath, "Testing"); | |
Sandbox.IO.File.WriteAllText(newPath, "Testing", System.Text.Encoding.Unicode); | |
using var stream = Sandbox.IO.File.OpenRead(filePath); var xml = new System.Xml.XmlDocument(); xml2.Load(stream); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment