/// <summary>
/// 读取PDF文件
/// </summary>
/// <param name="fName">文件名称(可以从其他地方传进来)</param>
/// <returns></returns>
public FileStreamResult readPDF(string fName = "pdf文件.pdf")
{
string dirp = @"pdf文件的文件夹路径";
DirectoryInfo mydir = new DirectoryInfo(dirp);
string pdfSrc = string.Empty;
foreach (FileSystemInfo fsi in mydir.GetFileSystemInfos())
{
if (fsi is FileInfo)
{
FileInfo fi = (FileInfo)fsi;
string x = System.IO.Path.GetDirectoryName(fi.FullName);
string s = System.IO.Path.GetExtension(fi.FullName);
if (fi.Name == fName)
{
pdfSrc = dirp + "\\" + fi.Name;//pdf路径
ViewBag.title = fi.Name;//网页标题
}
}
}
FileStream fs = new FileStream(pdfSrc, FileMode.Open, FileAccess.Read);
return File(fs, "application/pdf");
}