2012-07-25 96 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

相關問題