上篇贴子讲述了如何显示报表的数据内容,但这样显示出来的报表有个问题,那就是报表中的图片无法显示(如报表的logo,Chart图片等)。
网上有贴子讲述此问题,但在Sharepoint2010中貌似有些差异。我们在报表的图片位置查看图片链接时可以看到类似如下内容:
http://sharepoint-dev:2010/sites/StarCompany/_layouts/Solutions/CrystalImageHandler.aspx?dynamicimage=cr_tmp_image_a6f5a0d8-80f9-4a2b-a04b-169a49e10a53.png
也就是说,Crystal Report使用到了CrystalImageHandler.aspx来显示图片,因为在我们的Sharepoint网站中没有此Handler,所以网上做法是使用
步骤一在Sharepoint项目的Layout对应目录下创建一个CrystalImageHandler.aspx
CrystalImageHandler.aspx内容如下
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<%@ Register Assembly="CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<%@ Register Assembly="CrystalDecisions.Shared, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CrystalImageHandler.aspx.cs" Inherits="StarCompanySpSolutions.Layouts.Solutions.CrystalImageHandler" DynamicMasterPageFile="~masterurl/default.master" %>
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server"></asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"></asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">Application Page</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >My Application Page</asp:Content>
CrystalImageHandler.aspx.cs内容如下
{
protected void Page_Load(object sender, EventArgs e)
{
// get the Crystal Reports temporary file name
String strtempImagePath = Request.QueryString["dynamicimage"];
if (strtempImagePath != null)
{
// send the temporary image file
SPWeb thissite = SPControl.GetContextWeb(Context);
String strsitename = thissite.Site.HostName;
int iport = thissite.Site.Port;
String strport = Convert.ToString(iport);
Response.TransmitFile(@"C:\WINDOWS\Temp\cr_tmp_image__" +
strsitename + strport + "\\" + strtempImagePath);
}
}
}
此方法作了偿试,但问题是在Sharepoin2010中,CrystalReport并没有在C:\WINDOWS\Temp\目录下创建临时文件,所以使用Response.TransmitFile(@"C:\WINDOWS\Temp\cr_tmp_image__" + strsitename + strport + "\\" + strtempImagePath);在Sharepoint2010中行不通。手功创建的Handler将找不到Crystal Report动态创建的临时图片文件。于是进一步偿试
步骤二:修改Webconfig文件。修改你自己的Sharepoint网站的Webconfig文件
在其<system.web>的<httpHandlers>节中加入如下内容:
< add verb ="GET" path ="CrystalImageHandler.aspx" type ="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
< add verb ="*" path ="GenerateImage.ashx" type ="GenerateDynamicImage" />
</ httpHandlers >
在<system.webServer>的<handlers />节中加入如下内容:
< add name ="CrystalImageHandler.aspx" verb ="GET" path ="CrystalImageHandler.aspx" type ="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition ="integratedMode" />
</ handlers >
保存修改,重启网站,使刚才的修改生效,在网站中打开水晶报表,终于看到了报表中的图片内容以及图表内容。
注:在修改Webconfig时,请
1、保存好修改前的Webconfig文件。
2、要检查你自己的Crystal report版本,本例使用的Version号是13.0.2000.0,而你的代码可能要随着你自己的Crystal Reprot版本号要作适当修改
相关链接: Sharepoint学习笔记---如何在Sharepoint2010网站中整合Crystal Report水晶报表(显示数据 一)
相关链接: Sharepoint学习笔记---如何在Sharepoint2010网站中整合Crystal Report水晶报表(显示数据 二)
相关链接: Sharepoint学习笔记---如何在Sharepoint2010网站中整合Crystal Report水晶报表(报表登录处理)