【问题标题】:Solution could not found FileStreamResult mvc5解决方法找不到 FileStreamResult mvc5
【发布时间】:2014-11-06 22:47:45
【问题描述】:

我正在处理一个 mvc5 项目,有时我需要能够使用该应用程序打印文档。问题是我收到此错误。

错误找不到类型或命名空间名称“FileStreamResult” (您是否缺少 using 指令或程序集引用?)

我在业务逻辑上的解决方案参考如下所示:

using System;    
using System.Collections.Generic;    
using System.Data;    
using System.Data.Entity;    
using System.Linq;    
using System.Web;    
using System.Web.Mvc;    
using Conference.Models;    
using System.IO;    
using iTextSharp.text;    
using iTextSharp.text.pdf;    
using System.Net.Mail;    
using System.Text;    
using System.Web.Helpers;

我在业务逻辑上的方法是这样的:

  public FileStreamResult PrintPdf(int id)
        {


            // Set up the document and the MS to write it to and create the PDF writer instance
            MemoryStream ms = new MemoryStream();
            Document document = new Document(PageSize.A4, 0, 0, 0, 0);
            PdfWriter writer = PdfWriter.GetInstance(document, ms);
            //var obj = new simphiwe();
            var obj = new DataContext();

            // Open the PDF document
            document.Open();

            // Set up fonts used in the document
            Font font_heading_3 = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.RED);
            Font font_body = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 9, BaseColor.BLUE);

            // Create the heading paragraph with the headig font
            Paragraph paragraph;
            paragraph = new Paragraph("Surgery", font_heading_3);
            Paragraph paraslip;
            paraslip = new Paragraph("**********************Document Records***********************");

            // Add image to pdf    
            // Create the heading paragraph with the headig font
            var info = from x in obj.Print
                       where x.Doc_Id == (id)
                       select x;

            foreach (var q in info)
            {
                //paragraph;
                // Add a horizontal line below the headig text and add it to the paragraph
                iTextSharp.text.pdf.draw.VerticalPositionMark seperator = new iTextSharp.text.pdf.draw.LineSeparator();
                seperator.Offset = -6f;

                PdfPTable table1 = new PdfPTable(1);
                PdfPTable table = new PdfPTable(1);
                PdfPTable table3 = new PdfPTable(1);
                PdfPTable table7 = new PdfPTable(1);
                table.WidthPercentage = 80;
                table3.SetWidths(new float[] { 100 });
                table3.WidthPercentage = 80;
                table7.SetWidths(new float[] { 100 });
                table7.WidthPercentage = 80;
                PdfPCell cell = new PdfPCell(new Phrase(""));
                cell.Colspan = 3;
                table1.AddCell(cell);
                table7.AddCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + "Surgery" + "\n\n" +
                  "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t+ "**********************Document Record***********************");
                table.AddCell("Document Number    : " + q.Doc_Id);
                table.AddCell("Patient Name         : " + q.Name);
                table.AddCell("Document Comment: " + q.Content);

                var d = new PrintRepository();
                PrintData diet = d.GetById(q.Doc_Id);
                table.AddCell("Doc_ID  :" + diet.Doc_Id);

                table.AddCell("Date Issued : " + DateTime.Today.Day + "/" + DateTime.Today.Month + "/" + DateTime.Today.Year);
                table.AddCell(cell);
                document.Add(table3);
                document.Add(table7);
                document.Add(table1);
                document.Add(table);
                document.Close();
            }
            byte[] file = ms.ToArray();
            MemoryStream output = new MemoryStream();
            output.Write(file, 0, file.Length);
            output.Position = 0;
            FileStreamResult f = new FileStreamResult(output, "application/pdf");
            return f; //File(output, "application/pdf"); //new FileStreamResult(output, "application/pdf");
        }
    }

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-5


    【解决方案1】:

    清理您的解决方案,然后将 System.Web.Mvc 的属性设置为 Copy Local = True。

    或者尝试从nuget重新安装mvc:http://www.nuget.org/packages/Microsoft.AspNet.Mvc

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-09
      • 1970-01-01
      • 1970-01-01
      • 2021-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多