我使用VB.NET构建了一个Web Matrix站点。我添加了一个名为reports.aspx的文件来处理一些报告。具体来说,它使用Neodynamic Web Client Print SDK将报告从SSRS保存到PDF,然后重定向到一个名为reports.ashx的处理程序文件,该文件实际上处理打印。
来自reports.aspx的代码
<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Microsoft.Reporting.WebForms" %>
<%-- Register the WebClientPrint script code --%>
<%=Neodynamic.SDK.Web.WebClientPrint.CreateScript(MyUtils.GetWebsiteRoot() + "reports.ashx")%>
<!DOCTYPE html>
<script language="VB" runat="server">
Private Sub Page_Load(sender As Object, e As EventArgs)
Dim reportname As String
Dim paramBlock As New ReportParameter()
Dim paramID As New ReportParameter()
reportname = Request("reportname")
Dim v As New ReportViewer
v.ProcessingMode = ProcessingMode.Remote
Dim serverreport As New ServerReport
serverreport = v.ServerReport
serverreport.ReportServerUrl = New Uri("http://websql1.core.com/Reports")
serverreport.ReportPath = "/Reports/Aramid/Sheeter/" & reportname
Select Case reportname
Case Is = "NomexBlockCard" Or "NomexBlockLabel" Or "NomexInternalLabel"
paramBlock.Name = "paramBlock"
paramBlock.Values.Add(Request("paramBlock"))
Dim parameters() As ReportParameter = {paramBlock}
Case Is = "NomexRoutingData"
paramID.Name = "paramID"
paramID.Values.Add(Convert.ToInt32(Request("paramID")))
Dim parameters() As ReportParameter = {paramID}
End Select
serverreport.SetParameters(parameters)
Save(serverreport, "~/Files/")
'now print
Response.Redirect("reports.ashx?fileName=" & reportname)
End Sub
Public Sub Save(ByVal sr As ServerReport, ByVal savePath As String)
Dim Bytes() As Byte = sr.Render("PDF", "", Nothing, Nothing, Nothing, Nothing, Nothing)
Using Stream As New FileStream(savePath, FileMode.Create)
Stream.Write(Bytes, 0, Bytes.Length)
End Using
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
</body>
</html>
来自reports.ashx的代码
<%@ WebHandler Language="VB" Class="reports" %>
Imports System
Imports System.Web
Imports Neodynamic.SDK.Web
Public Class reports : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim useDefaultPrinter As Boolean = True '(context.Request("useDefaultPrinter") = "checked")
Dim printerName As String = context.Server.UrlDecode(context.Request("printerName"))
Dim fileName As String = context.Server.UrlDecode(context.Request("fileName"))
Dim filePath As String = "~/Files/"
If (filePath <> Nothing) Then
Dim file As New PrintFile(context.Server.MapPath(filePath), fileName)
Dim cpj As New ClientPrintJob()
cpj.PrintFile = file
If (useDefaultPrinter OrElse printerName = "null") Then
cpj.ClientPrinter = New DefaultPrinter()
Else
cpj.ClientPrinter = New InstalledPrinter(printerName)
End If
cpj.SendToClient(context.Response)
End If
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
当我打开Visual Studio进行构建和发布时,我收到以下错误。
&#34; 从模块system.web的程序集导入类型system.web.httpcontextbase &#34;
当我查看reports.aspx中的代码时,
行下会出现错误Dim v as New ReportViewer
错误更正选项表示System.Web.Extensions version = 3.5.0.0,....需要&#34; 引用,包含已实现的接口System.Web.UI.IScriptControl。在项目中添加一个&#34;
我正在引用System.Web,System.Web.Extensions和System.Web.Abstractions。
定位.NET 4
请帮助我理解这个问题或需要了解的内容。
谢谢!
答案 0 :(得分:1)
事实证明这很简单。当我在Webmatrix中启动项目时,随着它的发展,我将其转移到Visual Studio解决方案中。当我将其移动到解决方案时,它将目标框架更改为2.0而不是4。
奇怪。将目标更改回4,更新了参考资料并且好了!