.net mvc记录下载日志txt
2019-08-29 本文已影响0人
孤傲小狼
参考链接:https://bbs.csdn.net/topics/300153370
https://blog.csdn.net/u010452388/article/details/78220659
/// <summary>
/// 下载客户端zip文件
/// </summary>
public void DownloadClient()
{
string url = "D:/InstallationPackage/AlituoclientInstall.zip";
string recordurl = "D:/InstallationPackage/downloadrecord.txt";
//Server.MapPath("~/")虚拟路径函数
DownloadFile(url);//上一篇文章又下载函数
Thread.Sleep(100);
WriteRecord(recordurl);//记录下载日志
}
//创建日志txt文档
public void WriteRecord(string recordurl)
{
StreamWriter sw;
//判断是否已经有了这个文件
if (System.IO.File.Exists(recordurl))
{
using (sw = System.IO.File.AppendText(recordurl)) //如果文件存在,则在文件末尾续写
{
sw.WriteLine(DateTime.Now + "测试");
}
}
else
{
using (sw = System.IO.File.CreateText(recordurl)) //创建文件,并写入内容
{
sw.WriteLine(DateTime.Now + "测试");
}
}
}