发送要下载的文件后显示消息
在发送要下载的文件后,我想在我的aspx页面上更新一些内容。 (之前显示的一些错误消息。)。 我相信这是不可能的,但你会给我一个解决方案吗?
以下是发送文件以供下载的代码:
Response.ContentType = "Application/zip"; Response.AddHeader("Content-Disposition", "attachment; filename=" + e.CommandArgument); Response.BinaryWrite(fileStream.ToArray()); Response.Flush(); Response.Close(); Response.End();
编辑澄清:我也相信没有合理的解决方案。 但是,可能有一个我不知道的Javascript技巧。
这是我能想象到的最简单的方式。
Click here to Download
在我的代码背后我有
protected void Page_Load(object sender, EventArgs e) { if(Request["download"]=="1") { try { Response.ContentType = "html/text"; Response.AddHeader("Content-Disposition", "attachment; filename=file.txt"); Response.Write("content of the file"); Response.Flush(); Response.Close(); Response.End(); } catch (Exception) { //An error occurred Response.Redirect("Error.aspx"); } } }
由于它只是一个链接,如果找不到该文件,浏览器将显示“未找到”。 如果服务器端出现错误,则重定向到错误页面。 如果你想要一个更详细的解决方案,我建议使用XMLHttpRequest。
上述就是C#学习教程:发送要下载的文件后显示消息分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/983896.html