从服务器打开文件并发送到浏览器 [英] Open file from server and send to browser

查看:256
本文介绍了从服务器打开文件并发送到浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hey, In my asp.net 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))); 

这篇关于从服务器打开文件并发送到浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆