私はPDFファイルを作成する必要があります。このPdfファイルにはいくつかのデータが入っています。さて、主な要件は、私はPDFを作成した後、私はそれをダウンロードすることができるはずです。今、PDFが作成されていますが、ダウンロードできません。 そのMVCアプリケーション.. は、私は上記のコントローラは、ファイル名を取得したファイルを読み込み、PDFと ダウンロードを作成します作成後のPDFファイルのダウンロード
public class HoldFilesController : Controller
{
// GET: HoldFiles
string holdpath = ConfigurationManager.AppSettings["HoldPath"].ToString();
public ActionResult Index()
{
DirectoryInfo dirInfo = new DirectoryInfo(holdpath);
List<FileInfo> files = dirInfo.GetFiles().ToList();
return View("Index",files);
}
**The above controller gets filenames from a file directory**
public ActionResult ViewFile(string[] Name)
{
for (int i = 0; i < Name.Length; i++)
{
string filepath=holdpath + @"\" + Name[i];
string result;
using (StreamReader streamReader = new StreamReader(filepath))
{
result = streamReader.ReadToEnd();
}
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
Document document = new Document(PageSize.A4, 10, 10, 10, 10);
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
document.Open();
Paragraph paragraph = new Paragraph();
paragraph.Add(result);
document.Add(paragraph);
document.Close();
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment;
filename=MyFile.pdf");
Response.TransmitFile(Server.MapPath("~/Files/MyFile.pdf"));
Response.End();
Response.Close();
}
}
さらに、参照用のコードを共有していますのでご注意ください。 コードをデバッグすると、その文書が作成されているのがわかります。しかし、それは
'しかしit'のダウンロードに問題が発生したが - これを読んで、まさにトラブルあなたは – Equalsk
を抱えている説明:https://stackoverflow.com/a/7088233/1662459 –
作成されたpdfとレスポンスのバインディングは何ですか?あなたはファイルパスや応答のものを使用していませんが、何をすると思いますか? – romerotg