服务端自定义下载压缩文件位置
作者:互联网
Thread t = new Thread((ThreadStart)(() =>{
SaveFileDialog sfd = new SaveFileDialog();
//设置文件类型
sfd.Filter = "(*.zip;*.xls;*.xlsx)|*.et;*.xls;*.xlsx|all|*.*";
//设置默认文件类型显示顺序
sfd.FilterIndex = 1;
//保存对话框是否记忆上次打开的目录
sfd.RestoreDirectory = true;
//点了保存按钮进入
if (sfd.ShowDialog() == DialogResult.OK)
{
destinationZipFilePath = sfd.FileName.ToString(); //获得文件路径
string fileNameExt = destinationZipFilePath.Substring(destinationZipFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径
// destinationZipFilePath=destinationZipFilePath.Substring(0,destinationZipFilePath.Length- fileNameExt.Length);
//获取文件路径,不带文件名
//FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
//给文件名前加上时间
//newFileName = DateTime.Now.ToString("yyyyMMdd") + fileNameExt;
//在文件名里加字符
//saveFileDialog1.FileName.Insert(1,"dameng");
//System.IO.FileStream fs = (System.IO.FileStream)sfd.OpenFile();//输出文件
string sourceFilePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Files\\" + sourceFileName;
// destinationZipFilePath = ConfigurationManager.AppSettings["destinationZipFilePath"];
// destinationZipFilePath += sourceFileName + DateTime.Now.ToString("yyyyMMddHHmmss")+".zip";
//tag=1 成功
tag = 1;
}
else if (sfd.ShowDialog() == DialogResult.Cancel)
{
//已取消保存
tag = 2;
}
else
{
//保存失败
tag = 3;
}
}));
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
标签:自定义,文件名,fileNameExt,压缩文件,tag,ToString,destinationZipFilePath,sfd,服务端 来源: https://www.cnblogs.com/zxdz/p/13550130.html