请问,我做的任务是从Ftp下载东西保存到当地,但是我想让提示个保存路径的框,改怎么做?求指教~C#+.net
我想做个跟咱们普通下载时候一样的东西,让用户自己选择存储路径,这样方便用户,我也不用考虑地址问题!第一次做这个求指教谢谢~...
我想做个跟咱们普通下载时候一样的东西,让用户自己选择存储路径,这样方便用户,我也不用考虑地址问题!第一次做这个求指教谢谢~
展开
2个回答
展开全部
private void FileDownLoad(string filename)
{
string destFileName = filename;
//destFileName = Server.MapPath("./") + destFileName;
destFileName = Server.UrlDecode(destFileName);
if (File.Exists(destFileName))
{
FileInfo fi = new FileInfo(filename);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = true;
Response.Charset = "GB2312";
//添加头信息,为 "文件下载/另存为 "对话框指定默认文件名
Response.AppendHeader("Content-Disposition", "attachment;filename="
+ HttpUtility.UrlEncode(Path.GetFileName(destFileName),
System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "text/plain";
Response.Filter.Close();
Response.WriteFile(destFileName);
Response.Flush();
Response.End();
}
else
{
Response.Write("<script language = javascript>alert('下载出错')</script>");
}
}
{
string destFileName = filename;
//destFileName = Server.MapPath("./") + destFileName;
destFileName = Server.UrlDecode(destFileName);
if (File.Exists(destFileName))
{
FileInfo fi = new FileInfo(filename);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = true;
Response.Charset = "GB2312";
//添加头信息,为 "文件下载/另存为 "对话框指定默认文件名
Response.AppendHeader("Content-Disposition", "attachment;filename="
+ HttpUtility.UrlEncode(Path.GetFileName(destFileName),
System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "text/plain";
Response.Filter.Close();
Response.WriteFile(destFileName);
Response.Flush();
Response.End();
}
else
{
Response.Write("<script language = javascript>alert('下载出错')</script>");
}
}
追问
追答
string targetPath = Server.MapPath("~/DownLoadExcel");
NewExcelHelper excelHelper = new NewExcelHelper();
string execlname = "Leatime表" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx";
string fileFullPath = Path.Combine(targetPath, execlname);//路径
excelHelper.CreateExcelByDataTable(fileFullPath, dt2);//传datatable过去 生成文件的方法
excelHelper.Dispose();
FileDownLoad(fileFullPath);
方法参数代表是路径传到服务器的路径
DownLoadExcel 是你项目中自己建的一个文件夹名
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询