在导出水晶报表的时候,系统报如下错误

nzcsnewbie 2006-05-25 10:54:43
在导出水晶报表的时候,系统报如下错误
。。。Report\CrystalReport1.rpt 内出错:拒绝访问报表文件。其他程序可能正在使用它。

不导出的时候,水晶报表可以正常显示。可能是哪里出错了呢?

小弟是应用的PUSH模式,RPT文件关联到一个XSD强类型的DATASET中,显示没问题,但导出的时候遇到了上面的问题。有高人帮忙看一下吗?

导出代码如下:
CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
ReportDoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.RichText;
 DiskOpts.DiskFileName = "c:\\Output.rtf";
ReportDoc.ExportOptions.DestinationOptions = DiskOpts;

  ReportDoc.Export();


另有一贴,两贴并分一起给了。
http://community.csdn.net/Expert/topic/4777/4777292.xml?temp=.5322229
...全文
281 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
nzcsnewbie 2006-05-26
  • 打赏
  • 举报
回复
好了,谢谢”因为有你“的帮助。非常感谢。已经没问题了。
nzcsnewbie 2006-05-26
  • 打赏
  • 举报
回复
我在应用PUSH模式的时候,已经成功的加载了RPT文件,只是再导出的时候遇到了拒绝访问的问题。这也是对导出目录操作权限不足造成的吗?
xwdd129 2006-05-25
  • 打赏
  • 举报
回复
你这是导出时,对导出目录操作权限不足,请按上面方法解决
xwdd129 2006-05-25
  • 打赏
  • 举报
回复
一般来说,拒绝访问是权限问题!

一般的解决方法就是在这个目录上点击右键, 然后在"属性"中选择"安全", 然后添加ASPNET用户到当前用户列表中。不过如果有多个目录的话,这样的方法就需要反复的操作, 显得繁琐了一些。

另一个高效的方法是在"管理工具"中, 选择"系统工具"-"本地用户和组"-"组", 双击"Administrator", 然后把ASPNET用户添加进来
nzcsnewbie 2006-05-25
  • 打赏
  • 举报
回复
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data.SqlClient;

namespace myStudyProject.crystalReport
{
/// <summary>
/// crystal_push_model 的摘要说明。
/// </summary>
public class crystal_push_model : System.Web.UI.Page
{
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DropDownList ddlExportFileType;
ReportDocument ReportDoc;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面

ReportDoc = new ReportDocument();
ReportDoc.Load(Server.MapPath("CrystalReport1.rpt"));
#region 解决登录错误问题
// TableLogOnInfo logonInfo = new TableLogOnInfo();//
// foreach( CrystalDecisions.CrystalReports.Engine.Table tb in ReportDoc.Database.Tables)
// {
// logonInfo = tb.LogOnInfo;
// logonInfo.ConnectionInfo.ServerName = "(local)";
// logonInfo.ConnectionInfo.DatabaseName = "OnLineTakeAway051019";
// logonInfo.ConnectionInfo.UserID = "sa";
// logonInfo.ConnectionInfo.Password = "ss";
// tb.ApplyLogOnInfo(logonInfo);
//
// }
#endregion



string strCon = System.Configuration.ConfigurationSettings.AppSettings["forreport"];
SqlConnection con = new SqlConnection(strCon);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from Orders",con);
DataSet b=new DataSet();
da.Fill(b,"order");
DataSet2 a=new DataSet2();
for(int i=0;i<b.Tables[0].Rows.Count;i++)
{
a.Tables[0].ImportRow(b.Tables[0].Rows[i]);
}

//da.Fill(a,"order");

ReportDoc.SetDataSource(a);

CrystalReportViewer1.ReportSource = ReportDoc;
con.Close();
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
ReportDoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
switch (this.ddlExportFileType.SelectedItem.Text)
{
case "文本文件":
  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.RichText;//
  DiskOpts.DiskFileName = "c:\\Output.rtf";//
break;
case "PDF文件":
  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;//
  DiskOpts.DiskFileName = "c:\\Output.pdf";//
break;
case "Word文件":
  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;//
  DiskOpts.DiskFileName = "c:\\Output.doc";//
break;
case "Excel文件":
  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;//
  DiskOpts.DiskFileName = "c:\\Output.xls";//
break;
default:
break;
}
ReportDoc.ExportOptions.DestinationOptions = DiskOpts;
Response.Write(ReportDoc.IsLoaded);
  ReportDoc.Export();
}
}
}

4,818

社区成员

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

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