2012-07-20 19 views
6

चल रहा तो मैंExportToHttpResponse क्रिस्टल रिपोर्ट CRViewer

ExportToHttpResponse

पद्धति का उपयोग करके अपने वेब आवेदन के क्रम दर्शक में रिपोर्ट खोले बिना पीडीएफ करने के लिए एक क्रिस्टल रिपोर्ट निर्यात करने का प्रयास कर रहा हूँ बिना। जब पैरामीटर लोड करने की बात आती है, तो फ़ाइल नाम/पथ लोड करने के लिए सब कुछ ठीक से प्रतीत होता है। लेकिन जब मैं उस भाग को निष्पादित करता हूं जो पॉपअप डायलॉग बॉक्स बनाने का अनुमान लगाता है, तो उपयोगकर्ता को सहेजने, चलाने, किसी भी प्रकार के डाउनलोड के लिए रद्द करने का विकल्प कुछ भी नहीं होता है। कोई त्रुटि नहीं फेंक दी गई है। यह कोड के किसी भी भाग पर कदम नहीं उठा रहा है जिसे मैं जानता हूं। ऐसा लगता है कि ExportToHttpResponse लाइन चलाएं और उसके बाद कुछ भी न करें।

तो मैं उम्मीद कर रही थी किसी ने मुझे मैं कोड के साथ गलत क्या कर किया जा सकता है में कुछ दिशा दे सकता है नीचे पाया:

protected void ExportRptButton_Click(object sender, EventArgs e) 
     { 
      if (null != SelectedReport) 
      { 
       rptParams.Clear(); 
       rptParams = null; 

       // Get the report document 
       // string filePath = Server.MapPath(@"~\Reports\" + SelectedReport.FileName + ".rpt"); 
       // Declare a new Crystal Report Document object and load the report file into the report document. 
       ReportDocument rptDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); 
       ConfigureCrystalReports(rptDoc); 
       // repDoc.Load(rptFileName); 

       // AddParameters(); 
       // Set the report parameters the report object. 
       LoadParameterFields(rptDoc); 
       // Set the static text fields in the report object. 
       LoadStaticTextFields(rptDoc); 

       try 
       { 
        if (rptDoc.IsLoaded) 
        { 
         // Stop buffering the response 
         Response.Buffer = false; 
         // Clear the response content and headers 
         Response.ClearContent(); 
         Response.ClearHeaders(); 
         Response.ContentType = "application/pdf"; 
         // Export the Report to Response stream in PDF format and file name Customers 
         rptDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "DirectAccessReport"); 
         // rptDoc.ExportToDisk(ExportFormatType.PortableDocFormat, "~/PDF_Folder"); 
         // There are other format options available such as Word, Excel, CVS, and HTML in the ExportFormatType Enum given by crystal reports 
        } 
       } 
       catch (Exception ex) 
       { 
        logger.ErrorFormat("Could not export to pdf! {0}", ex);     
       } 
      } 
     } 

कुछ नोट: LoadParametersFields/LoadStaticTextFields तरीकों के ऊपर प्रदर्शित काम करने लगते हैं सही ढंग से और जब क्रूवर में रिपोर्ट खोलने के लिए उपयोग किया जाता है तो रिपोर्ट आती है और काम करती है। हालांकि, अगर आप उन तरीकों को देखना चाहते हैं तो मैं उन्हें अनुरोध पर फेंक दूंगा।

शुरुआत में rptParams एक निजी तौर पर List<ReportParameter>()

घोषित किया जाता है ConfigureCrystalReports विधि प्राप्त करने और रिपोर्ट के filepath लोड करने के लिए प्रयोग किया जाता है।

किसी भी मदद या सुझाव की सराहना की जाती है। धन्यवाद।

+0

कोशिश जोड़ने 'Response.Flush();' 'के बाद rptDoc.ExportToHttpResponse' – Icarus

+0

@Icarus मैं इसे करने की कोशिश की है, लेकिन यह किसी भी ध्यान देने योग्य परिवर्तन – James213

उत्तर

0

यह नमूना कोड मेरे लिए काम करता है; त्रुटि प्रबंधन को देखो।

protected void btnExport_Click(object sender, EventArgs e) 
{ 
    // Stop buffering the response 
    Response.Buffer = false; 
    // Clear the response content and headers 
    Response.ClearContent(); 
    Response.ClearHeaders(); 

    ExportFormatType format = ExportFormatType.PortableDocFormat; 
    string ext = ".pdf"; 
    string reportName= "myreport"; 

    try 
    { 
     reportDocument.ExportToHttpResponse(format, Response, true, reportName); 
    } 
    catch (System.Threading.ThreadAbortException) 
    { 
     //ThreadException can happen for internale Response implementation 
    } 
    catch (Exception ex) 
    { 
     //other exeptions will be managed 
     throw; 
    } 
} 
+0

नहीं किया मैंने कहा अपवाद जोड़ा लेकिन अभी भी कुछ नहीं फेंका गया था। – James213

संबंधित मुद्दे