/// <summary> /// 讀取數據,並以txt格式保存 /// </summary> /// <param name="data">數據源,文件內容</param> /// <param name="sort">文件夾名稱</param> public static String Sava ...
/// <summary>
/// 讀取數據,並以txt格式保存
/// </summary>
/// <param name="data">數據源,文件內容</param>
/// <param name="sort">文件夾名稱</param>
public static String SavaProcess(string data,string sort)
{
if (!string.IsNullOrEmpty(data))
{
System.DateTime currentTime = System.DateTime.Now;
//獲取當前日期的前一天轉換成ToFileTime
string strYMD = currentTime.ToString("yyyyMMddHHmmssfff");
//按照日期建立一個文件名
string FileName = strYMD + ".txt";
//獲取當前項目所在磁碟
string CurDir = System.Windows.Forms.Application.StartupPath.Substring(0, System.Windows.Forms.Application.StartupPath.IndexOf(':')) + ":\\" + @"SaveDir";
//判斷路徑是否存在
if (!System.IO.Directory.Exists(CurDir))
{
System.IO.Directory.CreateDirectory(CurDir);
}
string name =CurDir+"\\"+@""+sort+"";
if(!System.IO.Directory.Exists(name))
{
System.IO.Directory.CreateDirectory(name);
}
CurDir = name;
//不存在就創建
String FilePath = CurDir + "\\" + FileName;
////文件覆蓋方式添加內容
System.IO.StreamWriter file = new System.IO.StreamWriter(FilePath, false);
//保存數據到文件
file.Write(data);
//關閉文件
file.Close();
//釋放對象
file.Dispose();
return FilePath;
}
else
{
return "";
}