向网易下载附件一样 点击一个超链接可以选择打开文件,也可以选择保存文件。请给出代码。谢谢。
解决方案 »
- 急~~Datalist的编辑和取消问题
- MVC 新建了一个managementController,actionLink找不到management目录下的页面了,怎么回事?
- asp.net里动态加载的textbox如何设置multline属性
- asp.net如何自动添加表格的行,并写入数据?
- 刚刚涉足asp.net 调试出现 找不到存储过程 'sp_SessionList_AddItem'。如何解决??急
- 急急!!!!!!!!!!!!!!!!!!!!!解答对者有分
- 急呀,想了几天:有谁做个OA中的工作流系统呀,我个问题:在做工作流的时候:“退上一步办理人”怎么样做的呀,给点思路?
- dataGrid中分页,点击上一页、下一页,反复多点几次就找不到页面了??
- 请问如何实现datagrid控件的超级链接功能???
- 谁有excel.dll\word.dll\owc
- 水晶报表问题,请教高手,急啊
- ** 请问如何防止网页被整站下载 **
2 Page.Response.Clear();
3 //这里的ContentType也可以读存入数据库中的文件类型.
4 Page.Response.ContentType="Application/unknown";
5 //attachment是以附件的形式下载,也可以改为online在线找开.
6 Response.AddHeader("Content-Disposition","attachment; filename=" +
7 ds.Tables[0].Rows[0]["filename"].ToString() + ";");
8
9 Page.Response.BinaryWrite(file);
10 Page.Response.Flush();
11 Page.Response.End();
{
FileStream stream=null;
try
{
stream = new FileStream(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
int bufSize = (int)stream.Length;
byte[] buf = new byte[bufSize]; int bytesRead = stream.Read(buf, 0, bufSize);
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+System.IO.Path.GetFileName(physicalFilePath));
HttpContext.Current.Response.OutputStream.Write(buf, 0, bytesRead);
HttpContext.Current.Response.End();
}
finally
{
stream.Close();
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
DownloadFile(@"c:\1.txt");
}