1

我有一个位于 c:\inetpub\sites\website 的 ASP.NET MVC Web 应用程序

在其中,我可以选择下载 PDF 文件。

PDF 文件存储在其他地方,例如 c:\data\pdffiles

如果我设置了正确的权限,我可以从我的网络应用程序中的 c:\data\pdffiles 文件夹中读取吗

IIS APPPOOL{应用程序池名称}

问候

4

2 回答 2

4

Yes, you can do that from an ASP.NET MVC controller-action like this:

public FileResult Download()
{
    string filePath = @"c:\data\pdffiles\doc.pdf";
    byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
    string fileName = Path.GetFileName(filePath);

    return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Pdf, fileName);
}

Even shorter - if you don't want to override the filename when downloaded.

public FileResult Download()
{
    string filePath = @"c:\data\pdffiles\doc.pdf";

    return File(filePath, MimeMapping.GetMimeMapping(filePath));
}

If you need custom MIME types, see this answer: https://stackoverflow.com/a/14108040/2972

于 2017-01-10T11:53:20.670 回答
0

You can do that. For that you need to create virtual direct in IIS into your website and then you can use that virtual director which you can map to the folder other than the project folder

于 2017-01-10T11:54:12.800 回答