.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to display print preview from code ?

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :SharePoint
Hi i'm working on a winform app which hosted of infopath form. is there any way to display print preview of infopath form from code ? in my form, i've used this code to show print preview of the current infopath form : this.formControl1.XmlForm.Print(true); but i got this exception : Specified cast is not valid. can anybody help me where is my problem and how to work-around this ? thanks in advance http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx

View Complete Post

More Related Resource Links

Printing: Preview and Print from Your Windows Forms App with the .NET Printing Namespace


Printing is an integral part of every complete Windows-based application. Providing robust printing capabilities in these applications has often proved to be a tedious chore. Now, printing from Windows Forms with the .NET Framework means you must adopt a document-centric approach, resulting in cleaner and more manageable code. While the System.Windows.Forms namespace provides seamless integration with all the standard print dialogs (such as Print Preview, Page Setup, and Print), the System.Drawing.Printing namespace offers numerous classes for extensibility and customization. These classes, and how they provide access to printing capabilities, are covered here. Other useful techniques, such as printing in the background to allow the user to continue other tasks, is also explained.

Alex Calvo

MSDN Magazine February 2003

Infopath Changed Event code triggering in preview but not in web filler.

Hi there, I've written some code for a changed event hookup on a field in infopath 2010. The form is for submission to a sharepoint 2010 forms library. What the code does is fill in a specific value into a field depending on the selected value from a combo-box elsewhere on the form. When i preview this in Infopath 2010 it works perfectly but when i fill out the form through the web interface it simply does nothing. I've got another piece of code which executes on load and this works perfectly in both the preview and the web filler. What it does is just set the value of a field when the form loads. Here is the code, could someone tell me what i'm doing wrong? public void InternalStartup() { EventManager.XmlEvents["/my:myFields/my:service_level"].Changed += new XmlChangedEventHandler(service_level_Changed); EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading); } public void service_level_Changed(object sender, XmlEventArgs e) { // Write your code here to change the main data source. XPathNavigator xroot = MainDataSource.CreateNavigator(); XPathNavigator serviceLevel = xroot.SelectSingleNode("/my:myFields/my:service_level",NamespaceManager); XPathNavigator xest = xroot.SelectSingleNode("/my:myFields/my:est_cost", NamespaceManager); switch (serviceLevel.Value)

Print Button +code in form

Using sharepoint 2010 and designed a simple form. How can I add the Print functionality to the ribbon from standard SP2010 NOT using Infopath? thx

"Live preview" while executing the code behind.

Hello!I have some code running behind - in example adding rows to the datable in loop.I have button which execute this procedure. Now I want to add textbox(?) or literal as well on my page.After each row which is added to the datable I want to write it in textbox/literal but without stopping the process.Something like that:1. User press the button.2. In textbox we have:-- Connecting ...-- Connected!-- Executing the code ...-- 1 row has been added. -- 1 row has been added. -- End of adding rows.How can I do this? 

Display UTF-8 code in GridView

Hi, I have a table in database, all table is utf-8 character set, one column is Italian another is Russian. I put as sqldatasource in a webform, correctly made the connection string. To show data from table i use GridView. Problem is that russian characters are not displayed correctly and some Italian characters, those with stress, for example "è" is not displayed correctly true. I put <globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/> in web.config file but no result and font selected for gridview is "Arial" Could you please help me? Best Regards     

Can't paste text into an Infopath form and see it with print preview

I have a user who says that they can't view any of their text that they cut and paste into the fields of a form when they choose Print Preview, in the forms library.  They're using IE8 to access the SharePoint site. When I access the same form in the same library from any browser from my computer, I can view pasted text in any field when I click Print Preview. Anyone see this before and can help me?? Thanks!    

Content cutoff in Print preview screen when a print button is clicked from a WPF application in Dell

Hello, I am facing a problem in printing.. I have a WPf+windows application running on the Dell Mini Net book(10") with screen resolution 1366 x 768. I am trying to the print the page with heading, image & some measurements on a 81/2 x 11. the print preview seem to be ok on the desktop(screen resolution 1440 x 900). but when i run same application in dell mini the layout is cutoff, the text is started from the footer area,  the page is not shown completely.. Can any one help me in this regard??   Thanks for the help in advance Archana

Print pdf from .fo file without preview



I have a file. xsl and its file. xml.
I need to print the result of merging the two files(.fo file) without the preview to the user and without saving the result (pdf) to disk.
is it possible?


Calendar does not print events, Print preview shows blank calendar


We are running SharePoint 2010 and when I do a print preview of a Calendar web part the preview shows a blank Calendar with no events, when I print there are no events printed either.  This is from a PC running Windows XP SP3 and IE7.  When I preview and print from the same computer using FireFox 3.6.10 the events are visible and print.

Since not all of our users have FireFox I need to find a way to get calendar printing to work from IE7.

Print option in InfoPath 2007 through Code

Hi All,

I am using the Info path 2007 web enabled. My requirements is to provide the Print option.

The Print option from standard tool bar i removed.

I need to print the current view form by using C# code.

I seached in net , i got help for Info Path 2003.I need help for Info path 2007 like PrintOut() in 2003.

Please help or suggest me to solve the requirements.

Code - Export To MSWord (Print Layout)


Below is the code to use to Export the ASP.Net Page to MS-Word.
The below code has a feature that it exports in 'Print Layout' mode and not in Web-Layout.
For this feature to work you need to remove the <header> tag from ASPX.

string fileNameWord = "PrintView.doc";

protected void Page_Load(object sender, EventArgs e)
    if (!Page.IsPostBack)
        BindPage(); // Your codt e to bind the page

public void ExportToMSWord(string fileNameWord)
    string strBody = string.Empty;
    strBody = @"<html xmlns:o='urn:schemas-microsoft-com:office:office' " +
    "xmlns:w='urn:schemas-microsoft-com:office:word'" +

    strBody = strBody + "<!--[if gte mso 9]>" +
    "<xml>" +
    "<w:WordDocument>" +
    "<w:View>Print</w:View>" +
    "<w:Zoom>100</w:Zoom>" +

Print Without Preview(Crystal Reports)


Guys, I have a page where details are been loaded. Then i have a print button. When i press that button it opens another page where crystal reports viewer is available and loads the report and convert it to PDF and displays it.

Now i need to modify it as it should straightly print when i press the print button rather than going and loading a crystal report viewer. 

Any suggestions please? I tried the PrintToPrinter method, but its not working. I dont want the javascript Window.Print. please help me with any other suggestions.

CreatePage.aspx cannot display page layout preview image


I am using a custom site template and functions fine, except that when I get to the CreatePage.aspx page, the preview image is not displayed. When I looked up the properties on that image, it was looking for the image in a location other than the place where it should.

For eg: Instead of looking for it at /_catalogs/masterpage/en-US/Preview%20Images/ArticleBodyOnly.png  it looks for it at xxx/test/_catalogs/masterpage/en-US/Preview%20Images/ArticleBodyOnly.png where xxx was an external consultant that worked on this site before me and I am new to sharepoint. The only scenario when this doesnt happen is for the DefaultPageLayout.png file.

This problem seems to repeat everytime I use this site template. When I open up the sites with these templates on Sharepoint Designer, I can see all the preview images over there. For some reason, the CreatePage.aspx is not looking for the images in this location and looks for it at another location.

I am really stuck with this issue, can someone please help me understand why this is happening or help me resolve this?


Source Code Display


Does anyone know how to make my source code to display on one line instead of multiple in source view.  The display drives me batty when I'm trying to find something and I would prefer to display across the page instead of multiple lines down the page. 

Data Points: Entity Framework Preview: code first, ObjectSet and DbContext


With the code first feature in Entity Framework, there is no visual data model and no XML describing that model. You simply create the classes for your application domain and go. We'll show you this and several other nifty new features in the latest EF CTP.

Julie Lerman

MSDN Magazine October 2010

Printing and Print Preview hangs on a large report


Using SQL Server 2008 R2 Cumlative Update #4 (build 10.50.1746)

A report that is 119 pages long hangs after page 113 in both the print preview and printing.

A different report that is 90 pages long hangs on page 60 in both the print preview and printing.

These reports worked fine before applying the cumulative update #4.

Print Preview diaplays balnk for SSRS reports in ASP.NET

We have some Sql Server Reporting Services server reports in ASP.NET pages using report viewer. After page loads when we try to see print preview option in the File menu it displays blank page (does not display any content of report part). Any help is appreciated. 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend