You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
52 lines
1.5 KiB
4 years ago
|
using System.IO;
|
||
|
using System.Reflection;
|
||
|
using System.Text;
|
||
|
|
||
|
namespace CK.SCP.Utils
|
||
|
{
|
||
|
public static class FileHelper
|
||
|
{
|
||
|
public static string GetApplicationPath()
|
||
|
{
|
||
|
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
|
||
|
path = path.Replace(@"file:\", "");
|
||
|
if (path.Substring(path.Length - 1, 1) != @"\")
|
||
|
{
|
||
|
path += @"\";
|
||
|
}
|
||
|
return path;
|
||
|
}
|
||
|
|
||
|
public static void Create(string path)
|
||
|
{
|
||
|
if (!Directory.Exists(path))
|
||
|
Directory.CreateDirectory(path);
|
||
|
}
|
||
|
|
||
|
public static bool Exists(string filename)
|
||
|
{
|
||
|
filename = GetApplicationPath() + filename;
|
||
|
return File.Exists(filename);
|
||
|
}
|
||
|
|
||
|
public static void WriteFile(string filename, string str,bool isAppand = false)
|
||
|
{
|
||
|
filename = GetApplicationPath() + filename;
|
||
|
var sw = new StreamWriter(filename, isAppand, Encoding.Unicode);
|
||
|
sw.Write(str);
|
||
|
sw.Close();
|
||
|
}
|
||
|
|
||
|
|
||
|
public static string ReadFile(string filename,Encoding encoding= null)
|
||
|
{
|
||
|
if (encoding == null)
|
||
|
encoding = Encoding.Unicode;
|
||
|
filename = GetApplicationPath() + filename;
|
||
|
var sr = new StreamReader(filename, encoding);
|
||
|
var str = sr.ReadToEnd();
|
||
|
sr.Close();
|
||
|
return str;
|
||
|
}
|
||
|
}
|
||
|
}
|