使用c#下载Asp.net中的任何文件 [英] Download any File in Asp.net with c#
本文介绍了使用c#下载Asp.net中的任何文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我正在使用asp.net 2010.我上传图片,doc。,cdn服务器上的任何类型。
现在我想从cdn下载当我点击下载按钮然后任何弹出窗口应该打开选择位置(你要保存它的位置)时,然后应该在该选择的位置下载该文件。任何可以帮助我
谢谢&关于
Hi
I am using asp.net 2010. i have upload image, doc.,any type on cdn server .
now i want to download from cdn in such way as when i click on download button then any popup should be open for selectiong location ( where you want to save it.) then this file should be downloaded on that choosen location. any can help me
Thanks & regards
推荐答案
string result = Path.GetFileName(path);
//Response.ContentType = "Document/Docx";
Response.ContentType = "application/vnd.ms-word";
Response.AppendHeader("Content-Disposition", "inline; filename=" + result);
Response.TransmitFile(Server.MapPath(path));
Response.End();
这将有助于你...
http://aspalliance.com/259 [ ^ ]
http://support.microsoft.com/default.aspx?scid=KB;EN-US;q306654&ID=KB; EN-US; q306654& lex [ ^ ]
http://forums.asp.net/t/1265651.aspx/1 [ ^ ]
This will help you...
http://aspalliance.com/259[^]
http://support.microsoft.com/default.aspx?scid=KB;EN-US;q306654&ID=KB;EN-US;q306654&lex[^]
http://forums.asp.net/t/1265651.aspx/1[^]
Preferences oRefrence = new Preferences(UPLOADFOLDERTEMP); //类
string filename = oRefrence.VALUE + e.CommandName;
string fileName = string.Empty;
fileName = e.CommandName .substring(e.CommandName.IndexOf( - _ - )+ 3);
FileInfo fileinfo = new FileInfo(filename);
if(fileinfo.Exists)
{
Response.Clear();
Response.Charset =;
Response.AddHeader(Content-Disposition,attachment; filename =+ fileName);
Response.AddHeader(Content-Length,fileinfo.Length.ToString()) ;
Response.ContentType =application / octet-stream;
Response.TransmitFile(fileinfo.FullName);
System.Web。 HttpContext.Current.ApplicationInstance.CompleteRequest();
}
Preferences oRefrence = new Preferences("UPLOADFOLDERTEMP"); //Class
string filename = oRefrence.VALUE + e.CommandName;
string fileName = string.Empty;
fileName = e.CommandName.Substring(e.CommandName.IndexOf("-_-") + 3);
FileInfo fileinfo = new FileInfo(filename);
if (fileinfo.Exists)
{
Response.Clear();
Response.Charset = "";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.AddHeader("Content-Length", fileinfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.TransmitFile(fileinfo.FullName);
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
}
这篇关于使用c#下载Asp.net中的任何文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文