Click here to Skip to main content
15,911,762 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there,
I want to print the current page of my design.I am developing stand alone project in visual studio 2010 professional edition using c#.
So can anyone help me to print the current page?
Posted
Comments
SantoshRohinSantosh 7-Feb-12 6:43am    
No one there???

if you don't want to use JS functions then Use below process:

Process 1:

C#
#region PrintLogicNew
            string fileName = System.IO.Path.GetFileName(Request.Path).Substring(0, System.IO.Path.GetFileName(Request.Path).Length - 5);
            Utilities.Common obj_Common = new Utilities.Common();
            hdfPrintCacheId.Value = fileName + Session.SessionID + "Print";
            Cache.Insert(hdfPrintCacheId.Value, dvPrint, null, DateTime.MaxValue, TimeSpan.FromMinutes(Convert.ToDouble(ConfigurationSettings.AppSettings["CacheExpiryTime"])));
            #endregion


Process 2:

At HTML Page

HTML
<asp:hiddenfield id="hdfPrintCacheId" runat="server" xmlns:asp="#unknown" />
                                                                    <a href="#"  önclick="JavaScript:openPrintWindowWithQueryString('<%=hdfPrintCacheId.Value %>');">
                                        <img src="../Images/print.gif" style="border: none" /></a>


Above process will help you. :-D


==================================================================

If you want to use a JS function, then

JavaScript
function Clickheretoprint() {
            //            alert(document.getElementById("dvPrint"));
            var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
            disp_setting += "scrollbars=yes,width=650, height=600, left=100, top=25";
            var content_vlue = document.getElementById("dvNestedGridPrint").innerHTML;
            //            prefix = "<table width='100%' align='center' cellpadding='3' cellspacing='1' style='font-weight: bold; font: Arial-bold; font-size: 12px; background-color: #000;'> </table>";
            //            alert(content_vlue);
            var docprint = window.open("", "", disp_setting);
            docprint.document.open();
            docprint.document.write('<html><head><title>Approved BOM</title>');
            docprint.document.write('</head><body onLoad="self.print()"><center>');
            docprint.document.write(content_vlue);
            docprint.document.write('</center></body></html>');
            docprint.document.close();
            docprint.focus();
        }
 
Share this answer
 
Comments
SantoshRohinSantosh 7-Feb-12 5:39am    
Thanks dude but I am not doing project in Asp.net
It is stand alone project.
Can you please help me?
Hello,

It can be done with simple javascript i.e "window.print()"
 
Share this answer
 
Comments
SantoshRohinSantosh 7-Feb-12 5:45am    
Ya but compiler is not accepting that.
SantoshRohinSantosh 7-Feb-12 6:33am    
Do i need to include any assembly for that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900