2012-07-25 50 views
0

我从昨晚开始一直在寻找这个,并且无法弄清楚如何解决它。类型FileResult和FileStreamResult未定义,我该如何解决?

2个错误,一个说,Type FileResult is not defined

另一说,Type FileStreamResult is not defined

Imports System 
Imports System.IO 
Imports System.Collections.Generic 
Imports System.Text 
Imports EO.Pdf 
Imports System.Collections.Specialized 

Partial Class getRecs 
    Inherits System.Web.UI.Page 

Public Function Download() As FileResult 
     ' Populate list with urls 
     Dim qParams As String = Request.QueryString("p") 
     Dim urls() As String = qParams.Split(","c, ChrW(StringSplitOptions.RemoveEmptyEntries)) 

     Dim documents = New List(Of EO.Pdf.PdfDocument)() 
     For Each url In urls 
      Dim doc = New EO.Pdf.PdfDocument() 
      EO.Pdf.HtmlToPdf.ConvertUrl(url, doc) 
      documents.Add(doc) 
     Next 

     Dim mergedDocument As EO.Pdf.PdfDocument = EO.Pdf.PdfDocument.Merge(documents.ToArray()) 

     Dim ms = New MemoryStream() 
     mergedDocument.Save(ms) 
     ms.Position = 0 

     Return New FileStreamResult(ms, "application/pdf") With { _ 
     .FileDownloadName = "download.pdf" _ 
     } 
    End Function 

End Class 

在此先感谢。

+0

是否有可能你正在试图把MVC编码成WebForms的项目? – 2012-07-25 14:07:04

+0

@ J.Steen MVC和WebForms将很高兴地融合在同一个项目中。 – Richard 2012-07-25 14:08:35

+0

@Richard Quite,但是这将解释缺失的进口,正如你已经回答的那样。试图将OP引导至他们自己的解决方案。 =) – 2012-07-25 14:09:09

回答

1

我希望你缺少一个

Imports System.Web.Mvc 

,并可能给System.Web.Mvc集的引用。不是VS提供一点点下拉的未定义符号,将为您添加此? (我很少使用VB,因此不确定是否与C#相同。)

但是对于ASP.NET WebForms,您可能会发现HttpResponse.WriteFile是更好的方法。

+0

是的VS确实提供了一些下拉菜单。它给出了2个关于修复FileResult的建议。它说为FileResult或新类型创建一个类。我选择了“创建类”,FileResult的错误消失了,但我尝试了所有关于FileStreamResult的建议,但错误仍然存​​在。 – Kenny 2012-07-25 14:25:28

+0

@Kenny你有没有检查过你有程序集的参考? – Richard 2012-07-25 14:48:33

+0

感谢您的回复。是的,我做了检查,但没有看到一个。我可以没有这些fileResult/FileStreamResult的东西吗?事实上,我发现,我这里使用的示例代码: http://www.kristofclaes.be/ 用它来这里尝试并获得片断工作: http://www.essentialobjects.com/doc /4/htmltopdf/merge.aspx – Kenny 2012-07-25 15:05:24

相关问题