c# - Printing rdlc report without preview in web application in IIS mode -
there code in msdn printing rdlc without preview in web application not work when implement in iis...is there solution ....or code work in on print of rdlc without preview here link http://msdn.microsoft.com/en-us/library/ms252091.aspx not give exception not print report on msdn said create console application need in asp.net web application run in iis.
using system; using system.io; using system.data; using system.text; using system.drawing.imaging; using system.drawing.printing; using system.collections.generic; using microsoft.reporting.webforms; using system.data.sqlclient; using system.configuration; using system.collections; using system.web; using system.web.security; using system.web.ui; using system.web.ui.webcontrols; using system.web.ui.webcontrols.webparts; using system.web.ui.htmlcontrols; using system.windows.forms; ///<summary> /// summary description printing /// cool code found on msdn site print labels out without preview /// abhay maini ///</summary> publicclassprinting : idisposable { public printing() { // // todo: add constructor logic here // } publicint m_currentpageindex; publicilist<stream> m_streams; // routine provide report renderer, in order // save image each page of report. publicstream createstream(string name,string filenameextension, encoding encoding,string mimetype, bool willseek) { string currentdrive; currentdrive = application.startuppath.tostring();stream stream = newfilestream("c:\\labels\\" + name + "." + filenameextension, filemode.create); m_streams.add(stream); return stream; } publicvoid export(localreport report) { string deviceinfo = "<deviceinfo>" + " <outputformat>emf</outputformat>" + " <pagewidth>4.0in</pagewidth>" + " <pageheight>2.0in</pageheight>" + " <margintop>0.00in</margintop>" + " <marginleft>0.00in</marginleft>" + " <marginright>0.00in</marginright>" + " <marginbottom>0.00in</marginbottom>" + "</deviceinfo>"; warning[] warnings;m_streams = newlist<stream>(); report.render("image", deviceinfo, createstream, out warnings); foreach (stream stream in m_streams) stream.position = 0; } // handler printpageevents publicvoid printpage(object sender, printpageeventargs ev) { metafile pageimage = newmetafile(m_streams[m_currentpageindex]); ev.graphics.drawimage(pageimage, ev.pagebounds); m_currentpageindex++; ev.hasmorepages = (m_currentpageindex < m_streams.count); } publicvoid print(string printername) { // const string printername = printername; if (m_streams == null || m_streams.count == 0) return; printdocument printdoc = newprintdocument(); printdoc.printersettings.printername = printername; if (!printdoc.printersettings.isvalid) { string msg = string.format( "can't find printer \"{0}\".", printername); messagebox.show(msg, "print error");return; } printdoc.printpage += newprintpageeventhandler(printpage); printdoc.print(); } // create local report report.rdlc, load data, // export report .emf file, , print it. publicvoid run(string reportname, string printername, datatable mydatatable,string dsstring) { localreport report = newlocalreport(); report.reportpath = reportname; report.datasources.clear(); report.datasources.add(newreportdatasource(dsstring, mydatatable)); export(report); m_currentpageindex = 0; print(printername); } publicvoid dispose() { if (m_streams != null) { foreach (stream stream in m_streams) stream.close(); m_streams = null; } } } above class can called below behind text change event: protectedvoid txtscanid_textchanged(object sender, eventargs e) { string sqlprintscanid = "select [scanid], [loadid], [tempvrma], [custpalletid], [typeofasset] [serialscandetail] [scanid]=" + txtscanid.text + ""; string strconnection = configurationmanager.connectionstrings["revisionconnectionstring"].tostring(); sqlconnection conn = newsqlconnection(strconnection); sqldataadapter da = newsqldataadapter(); da.selectcommand = newsqlcommand(sqlprintscanid, conn); dataset ds = newdataset(); da.fill(ds, "revisiondataset_serialscandetail"); //reportviewer1.localreport.refresh(); newprinting.run(@"reports\report_scanid.rdlc", "eltron 2442", ds.tables[0], "revisiondataset_serialscandetail"); }
i suggest making use of reportviewer class.
reportviewer reportviewer = new reportviewer(); reportviewer.localreport.reportpath = "reportpath"; reportviewer.localreport.datasources.add(new reportdatasource("data", data)); byte[] byteinfo; byteinfo = reportviewer.localreport.render("image", deviceinfo, createstream, out warnings); memorystream ms = new memorystream(byteinfo); image returnimage = image.fromstream(ms); returnimage image data type can display/print.
i see making call render not assigning value use, combined not using report viewer problem.
the reason msdn suggest making console application is idea proof of concept in basic program such console, result want, port code desired environment.
Comments
Post a Comment