从服务器打开文件并发送到浏览器

编程入门 行业动态 更新时间:2024-10-23 23:22:49
本文介绍了从服务器打开文件并发送到浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嘿,在我的asp应用程序创建PDF文件并将其保存在App_Data文件夹服务器上。接下来我想打开这个文件,用户可以打印。

Hey, In my asp application I create pdf file and save it in App_Data folder on server. Next I want to open this file that user can print it.

如何打开浏览器中的这个文件?发送的HTTP头等等?有人有一些例子?

How to open this file in browser ? Send it in http header etc ? Someone have some examples?

请帮助;)

推荐答案

您可以将文件保存在文件夹中,然后给用户一个页面,在这里,他们可以点击链接来下载文件。只记得在文件中创建一个唯一的名称(使用GUID),​​否则用户将下载对方的文件。

you could save the file in a folder and then give the user a page where they can click on a link to download the file. just remember to create a unique name for the file (using guid) otherwise users will download each other's files.

您也可以在响应返回文件。以下code是返回一个Excel文件,但可以很容易地修改PDF。

you could also return the file in the response. the following code is for returning an excel file, but can be easily modified for pdf.

Response.ContentType = "application/vnd.ms-excel"; Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName)); Response.TransmitFile(Server.MapPath(string.Format("{0}/{1}", BasePath, fileName)));

更多推荐

从服务器打开文件并发送到浏览器

本文发布于:2023-11-23 01:21:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619600.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:浏览器   服务器   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!