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
The code you have shown represents a controller action that serves files from the
App_Code
folder. Serving files from arbitrary locations on the hard drive would be a huge security vulnerability. So I would recommend you sticking with this approach. But there are still flaws in this code. A malicious user could still display arbitrary files on your hard drive by using a specially crafted url. This could be fixed with the following action:and now you could use the
embed
tag to link to this controller action:or an
iframe
if you prefer:You may ise the
File
method of Controller class. This will return the PDF to browser.Assuming
SomeMethodToGetFullPathFromFileName
is a method which returns the full path to the PDF fileYou 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