如何在浏览器的外部文件夹中显示PDF文档 [英] How to displaying a PDF Document in outside folder in the Browser
问题描述
当前,我正在使用ASP.Net MVC 3作为文档管理系统的项目技术.我想显示位于我的硬盘驱动器中的文件夹中的pdf文档(C:,D:E:ect).我试图<embed>
标记.但这没用.它适用于我项目中的文件.我也不需要下载该pdf并阅读.我需要在我认为的某个地方分散它.
Currently i'm working with document management system project technology is ASP.Net MVC 3 . i want to display pdf document that is located in folder in my hard drive(C:,D: E: ect). i tried to <embed>
tag. but it didn't work. it worked for files inside my project. Also i don't need to download that pdf and read. i need to dispaly it somewhere in my view.
我看到了这段代码.但是我不知道该怎么用.
i saw this code segment. but i don't know how to use this..
public FileResult GetFile(string fileName)
{
Response.AppendHeader("Content-Disposition", "inline; filename=" + fileName + ";");
string path = AppDomain.CurrentDomain.BaseDirectory + "App_Data/";
return File(path + fileName, System.Net.Mime.MediaTypeNames.Application.Pdf, fileName);
}
有人可以帮助我解决此问题吗? 谢谢
Can someone help me to solve this problem. Thank You
推荐答案
您可能是 File
方法.这会将PDF返回到浏览器.
You may ise the File
method of Controller class. This will return the PDF to browser.
public ActionResult GetFile(string fileName)
{
string fullPathToFile=SomeMethodToGetFullPathFromFileName(fileName);
return File(fullPathToFile,"application/pdf","someFriendlyName.pdf")
}
假设SomeMethodToGetFullPathFromFileName
是一种将完整路径返回到PDF文件的方法
Assuming SomeMethodToGetFullPathFromFileName
is a method which returns the full path to the PDF file
您可以使用Server.MapPath
方法获取文件的完整(物理)路径.
You may use Server.MapPath
method to get the full (physical) path to the file.
如果您想在浏览器中查看它,可以像访问它一样
If you want to view this in the browser, you can access it like
yoursitename/someControllername/getfile?fileName=somepdffilenamehere
这篇关于如何在浏览器的外部文件夹中显示PDF文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!