?? 封裝.txt
字號:
#region 顯示客戶端對話框
/// <summary>
/// MessageBox用來在客戶端彈出對話框。
/// </summary>
/// <param name="TxtMessage">對話框顯示內容</param>
/// <returns></returns>
public string MessageBox(string TxtMessage)
{
string str;
str = "<script language=javascript>alert('" + TxtMessage + "')</script>";
return str;
}
#endregion
#region 創建文件夾
/// <summary>
/// 在客戶端制定的位置創建文件夾
/// </summary>
/// <param name="path"> 客戶端指定的路徑</param>
/// <returns></returns>
public bool CreateDirectory(string path)
{
try {
DirectoryInfo dt = new DirectoryInfo(path);
if (!dt.Exists)//如果文件夾不存在
{
dt.Create();//創建
return true;
}
else
{
return false;
}
}
catch (Exception)
{
throw;
}
}
#endregion
#region 刪除文件夾
/// <summary>
///DeleteDirectory 刪除指定路徑上的文件夾
/// </summary>
/// <param name="path">文件夾的路徑</param>
/// <returns></returns>
public bool DeleteDirectory(string path)
{
try
{
DirectoryInfo di = new DirectoryInfo(path);
if (di.Exists)//如果文件存在
{
di.Delete();//刪除
return true;
}
return false;
}
catch (Exception error)
{
throw error;
}
}
#endregion
#region 目錄檢索
private long fileSize = 0; //代表所有文件大小
private int fileNumber = 0; //代表該目錄下文件數量
/// <summary>
/// GetFile用來獲取指定文件夾下的文件大小,文件數量
/// 最后返回一個hashtable
/// </summary>
/// <param name="di"> 傳過來一個DirectoryInfo實例 </param>
/// <returns></returns>
public System.Collections.Hashtable GetFile(string path)
{
System.Collections.Hashtable hs = new System.Collections.Hashtable();
try {
DirectoryInfo di = new DirectoryInfo(path);
FileInfo[] file = di.GetFiles();
fileNumber += file.Length;
foreach (FileInfo temp in file)
{
fileSize += temp.Length;
}
hs.Clear();
hs.Add(fileNumber, fileSize);
return hs;
}
catch (Exception)
{
throw;
}
}
#endregion
#region 寫文件
/// <summary>
/// WriteFile用來在指定位置創建一個文件
/// </summary>
/// <param name="path">是傳過來的路徑</param>
/// <param name="text">是文件的內容</param>
/// <returns></returns>
public bool WriteFile(string path, string text)
{
try {
FileInfo f = new FileInfo(path);
if (f.Exists)
{
using (StreamWriter sw = f.CreateText())
{
sw.WriteLine(text);
return true;
}
}
return false;
}
catch (Exception)
{
throw;
}
}
#endregion
#region 讀文件
/// <summary>
/// ReadFile用來讀取指定路徑下文件的內容
/// </summary>
/// <param name="path">用來指定路徑</param>
/// <returns></returns>
public string ReadFile(string path)
{
try {
FileInfo f = new FileInfo(path);
if (f.Exists)
{
using (StreamReader sw = f.OpenText())
{
string s = sw.ReadLine();
return s;
}
}
return "";
}
catch (Exception)
{
throw;
}
}
public string ReadFile()
{
try
{
FileInfo f = new FileInfo("");
if (f.Exists)
{
using (StreamReader sw = f.OpenText())
{
string s = sw.ReadLine();
return s;
}
}
return "";
}
catch (Exception errror)
{
throw errror;
}
}
#endregion
#region 復制文件
/// <summary>
/// 復制文件到指定的文件中
/// </summary>
/// <param name="path1">源文件路徑</param>
/// <param name="path2">復制文件的路徑</param>
/// <returns></returns>
public bool CopyFile(String path1, string path2)
{
FileInfo fi = new FileInfo(path1);
if (fi.Exists)
{
fi.CopyTo(path2);//將指定路徑文件夾中的文件拷貝到該文件夾中,并將該文件改名
return true;
}
else
{
return false;
}
}
#endregion
#region 移動文件
public bool MoveFile(string path1,string path2)
{
FileInfo fi = new FileInfo(path1);
if (fi.Exists)
{
fi.MoveTo(path2);
return true;
}else
{
return false;
}
}
#endregion
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -