2009-03-11 26 views
1

ASP.NETページで、Crystal Report Viewer(CRV)からレポートを表示しているときに、レポートをPDFにエクスポートする機能があります)。エクスポートのデフォルトのファイル名は、CRVのIDです。Crystalレポートビューアでデフォルトのエクスポート名を設定する方法

デフォルト名は、レポートのパラメータに基づいて設定したいと考えています。 (例えば、「2008年の売上高」)。

私は、コードにPDFを生成し、ブラウザにストリームを生成するソリューションをコード化することができるページへのリンクを追加することができると知っていますが、 Crystal Reportsのこの誕生日。

+0

私はそのレポートのDocumentNameプロパティを信じています – sam

答えて

0

Visual Studio 2008を使用してレポートを作成する場合は、作成したReportClassを編集してDefaultNameプロパティを追加できます。

3
// You could pass the parameters to the web page 
// where you have theCrystalReportViewer control 
protected void Page_Load(object sender, EventArgs e) 
{ 
    string reportId = Request["rid"]; 
    string reportTitle = Request["rtitle"]; 

    ReportDocument reportDocument = HttpContext.Current.Session[reportId] as ReportDocument; 
    this.CommonCrystalReportViewer.ReportSource = reportDocument; 
    this.CommonCrystalReportViewer.DataBind(); 

    // Set the default export file name for the report. 
    this.CommonCrystalReportViewer.ID = reportTitle; 
} 
0

ReportViewerクラスの代わりに使用するReportExporterクラスがネイティブに存在しましたが、サポートされなくなりました。 3番目の部分も同様です。

私はこのコードサンプルを使用します(あなたはどこか別のセッション、のQueryStringまたはからまだ持っていない場合)

がレポートからパラメータ値を取得します

string myParamName="XXX"; 
object myParamValue; 
foreach (ParameterField field in reportDocument.ParameterFields) 
      { 
       if (string.Compare(field.Name.TrimStart('@'), myParamName, true) == 0) 
        myParamValue= field.CurrentValues; 
      } 

輸出

を必要とレポート名を使用して
string myReportName = "sales for " + myParamValue.ToString() + ".pdf"; 
try 
    { 
    reportDocument.ExportToHttpResponse( 
       ExportFormatType.PortableDocFormat 
       ,Response, true, myReportName); 
    } 
catch (System.Threading.ThreadAbortException) 
    { 
     //System.Threading.ThreadAbortException is thrown 
     //because, Response.End is called internally in ExportToHttpResponse method: 
    } 
-1
protected void Page_Init(object sender, EventArgs e) { 
    ... 
    // Set the default export file name for the report. 
    this.mainReportViewer.ID = reportTitle; 
    ... 
} 

reportVieweridPage_Initの機能であり、それ以外の場合は機能しません。

関連する問題