水晶报表导成word时候说:文件 c:\WINDOWS\TEMP\temp_8b05627a-af07-4d0b-bf12-5d45d2a53a0f.rpt 内出错:拒绝访问报表文件。其他程序可能

smjack 2006-11-03 08:54:41
我用.net2003的asp.net程序和水晶报表,发布在2003的系统下,开始还好用,突然有一天报错误文件 c:\WINDOWS\TEMP\temp_8b05627a-af07-4d0b-bf12-5d45d2a53a0f.rpt 内出错:拒绝访问报表文件。其他程序可能正在使用它。 temp_8b05627a-af07-4d0b-bf12-5d45d2a53a0f.rpt是每次访问的不同的临时文件,不知道为什么重启电脑都不好用,大家帮忙呀,以下是程序:
using System;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using System.Collections;
namespace webhello
{
/// <summary>
/// Export 的摘要说明。
/// </summary>
public class Export
{
private CrystalDecisions.CrystalReports.Engine.ReportClass rc;
private ExportFormatType format;
private string exportPath=System.Web.HttpContext.Current.Server.MapPath("")+"\\";
private string contentType="application/msword";
/// <summary>
/// 构造
/// </summary>
/// <param name="rpt">报表对象</param>
public Export(ReportClass rpt)
{
rc=rpt;
format=ExportFormatType.RichText;
exportPath+="temp.doc";
}
/// <summary>
/// 构造
/// </summary>
/// <param name="rpt">报表对象</param>
/// <param name="eft">导出格式</param>
public Export(CrystalDecisions.CrystalReports.Engine.ReportClass rpt,ExportFormatType eft)
{
rc=rpt;
format=eft;
string temp="";
switch(eft)
{
case ExportFormatType.Excel:
temp="temp.xls";
contentType="application/vnd.ms-excel";
break;
case ExportFormatType.PortableDocFormat:
temp="temp.pdf";
contentType="application/pdf";
break;
case ExportFormatType.RichText:
temp="temp.doc";
contentType="application/msword";
break;
case ExportFormatType.WordForWindows:
temp="temp.doc";
contentType="application/msword";
break;
}
exportPath+=temp;
}
/// <summary>
/// 导出报表
/// </summary>
public void ExportDocument()
{
ExportOptions crExportOptions=new ExportOptions();
DiskFileDestinationOptions crDestinationOptions=new DiskFileDestinationOptions();
crDestinationOptions.DiskFileName=exportPath;
crExportOptions=rc.ExportOptions;

crExportOptions.DestinationOptions=crDestinationOptions;
crExportOptions.ExportDestinationType=ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType=format;
rc.Export();

System.Web.HttpResponse Response=System.Web.HttpContext.Current.Response;

Response.ClearContent();
Response.ClearHeaders();
Response.ContentType=contentType;
Response.WriteFile(exportPath);
Response.Flush();
Response.Close();

try
{
System.IO.File.Delete(exportPath);
}
catch
{
}
}
/// <summary>
/// 设置报表参数
/// </summary>
/// <param name="ht">哈希表,参数字段名与参数值的键对集合</param>
public void SetParameters(Hashtable ht)
{
if(ht==null) return;
if(ht.Count==0) return;
//报表定义
ReportDefinition reportdef=rc.ReportDefinition;
//报表对象集
ReportObjects reportobj=reportdef.ReportObjects;
//字段对象
FieldObject fo=null;
//字段对象定义
FieldDefinition fieldDef=null;
//参数字段定义
ParameterFieldDefinition parafieldDef;
//参数字段集
ParameterFields paramFields = new ParameterFields();
//参数字段
ParameterField paramField = new ParameterField();
//参数字段离散值
ParameterDiscreteValue discreteVal = new ParameterDiscreteValue();
foreach(object key in ht.Keys)
{
try
{

fo=(FieldObject)reportobj[key.ToString()];
fieldDef=fo.DataSource;
parafieldDef=(ParameterFieldDefinition)fieldDef;
paramField.ParameterFieldName=key.ToString();
discreteVal.Value=ht[key];
paramField.CurrentValues.Add(discreteVal);
parafieldDef.ApplyCurrentValues(paramField.CurrentValues);
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex.InnerException);
}
}

}
}
}

...全文
381 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xwdd129 2006-11-04
  • 打赏
  • 举报
回复
ASPNET用户在导出目录的权限是否正确
nwgogogo 2006-11-03
  • 打赏
  • 举报
回复
可能是你重新发布网站后直接覆盖了源文件,造成新的报表和IE缓存的报表不一致。
直接重起服务器,然后删除IE缓存文件就行了。

4,818

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧