解决方案找不到FileStreamResult mvc5

时间:2014-06-23 14:07:30

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

我正在开发一个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");
        }
    }

1 个答案:

答案 0 :(得分:0)

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

或者尝试从nuget:http://www.nuget.org/packages/Microsoft.AspNet.Mvc

重新安装mvc