How to write C# Code for custom print button? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

How to write C# Code for custom print button?

Last post 01-27-2012 04:17 AM by Beircheart. 13 replies.
Page 1 of 1 (14 items)
Sort Posts: Previous Next
  • 10-29-2010 08:29 PM

    How to write C# Code for custom print button?

    Hi All,

    I have added a custom print button to browser based infopath form.

    I want to add code behind for this button. Does anyone know the exact c# code for this?

    Thanks,

    Rahul Babar

    ================================================
    ASP.NET, C#, Sharepoint 2007/2010/2013/SP Online, Infopath 2007/2010/2013 Admin/Developer
  • 10-29-2010 09:09 PM In reply to

    Re: How to write C# Code for custom print button?

     hi, you can use this.print(); it requires Full Trust and publishing through Central Admin (publish as admin-approved).

    Browser forms are translations of the infopath client form template, the formatting is almost never exactly the same, and some settings can change.  it's really difficult to get the print view to be exactly the same in a browser form.

  • 10-29-2010 09:22 PM In reply to

    Re: How to write C# Code for custom print button?

    I don't see print function for "this" object, am I missing something?

    Rahul Babar

    ================================================
    ASP.NET, C#, Sharepoint 2007/2010/2013/SP Online, Infopath 2007/2010/2013 Admin/Developer
  • 10-30-2010 05:58 AM In reply to

    Re: How to write C# Code for custom print button?

    hi, verify your codes language is c# and not c#2003. On option, form option, programming and select c#.

  • 11-01-2010 10:19 PM In reply to

    Re: How to write C# Code for custom print button?

    I verified it and its C# only.

    Rahul Babar

    ================================================
    ASP.NET, C#, Sharepoint 2007/2010/2013/SP Online, Infopath 2007/2010/2013 Admin/Developer
  • 11-02-2010 02:01 AM In reply to

    Re: How to write C# Code for custom print button?

    The Print() method is not available in browser forms.  I think it's unlikely that InfoPath provides a way to initiate a print action from a browser form.  Your best bet is probably to switch the form to a print view and instruct the user to manually print the page.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 11-02-2010 02:10 AM In reply to

    Re: How to write C# Code for custom print button?

    I had this requirement once, to print the form on button click. For this , i first created an excel template and created a form there exactly similar to Infopath form using excel VSTA, and then i took the print using excel functionality.

    Vishal Srivastava
    Senior Software Engineer
    SDG Software Pvt Ltd
  • 08-31-2011 07:13 AM In reply to

    Re: How to write C# Code for custom print button?

    Hi,

    I was also looking to create a custom Print Preview button and I'd just like to post how I eventually achieved this.

    After much searching without much luck, I decided to examine the existing Print Preview button. I included it in my form, clicked it and viewed the properties of the pop up window. Here it showed the following URL: https://<Server>/<Site>/_layouts/Print.FormServer.aspx. I then looked for a suitable parameter to pass to it and found that the following works: ///MyTestForm.xml?OpenIn=Browser">https://<Server>/<Site>/_layouts/Print.FormServer.aspx?XmlLocation=https://<Server>/<Site>/<List>/MyTestForm.xml?OpenIn=Browser

    I created a hyperlink in my Infopath 2010 Browser based form. I then created a field and set the default value as follows: concat(SharePointSiteUrl(), "_layouts/Print.FormServer.aspx?XmlLocation=", SharePointListUrl(), DocumentName, "xml?OpenIn=Browser")

    I then created a hyperlink with the value of that field and it works well for me

    Maybe this will be of use to someone

    All the best,

    Ben

  • 01-27-2012 02:12 AM In reply to

    Re: How to write C# Code for custom print button?

     

    Hi ,

     i was using the above Formula in my info path form 2010  to display the hyperlink but how to put DocumentName    in my form please give me a idea about that.

    I created a hyperlink in my Infopath 2010 Browser based form. I then created a field and set the default value as follows: concat(SharePointSiteUrl(), "_layouts/Print.FormServer.aspx?XmlLocation=", SharePointListUrl(), DocumentName, "xml?OpenIn=Browser")

  • 01-27-2012 02:29 AM In reply to

    Re: How to write C# Code for custom print button?

    Hi shahripu,

    In my case, DocumentName was simply a field I created. So DocumentName could be replaced with some field in your form that holds the file name

    As for what value my DocumentName field was equal to:

     The first time i save my form using a custom save button, I set the DocumentName to concat(../../my:CurrentUserName, "-", ../../../my:Descriptors/my:ProgrammeTitle) and using a submit data connection, I would submit it to the library using DocumentName as a file name

    Does that clear things up?

    All the best,

    Ben

  • 01-27-2012 03:17 AM In reply to

    Re: How to write C# Code for custom print button?

     Hi Ben ,

      As you told above  i added the  field and give the name DocumentName but further how to know this field hold the file name and how to set value of this field as you did above .please give me idea step by step for this process. i have need to display the document name when published info-path form is saved on document library in SharePoint 2010

  • 01-27-2012 03:35 AM In reply to

    Re: How to write C# Code for custom print button?

    Are you using a custom Save button (i.e Using Submit data connection to submit your form to the library) or are you using the standard built in save icon in the toolbar?

  • 01-27-2012 03:42 AM In reply to

    Re: How to write C# Code for custom print button?

     hi ,i am using the standard built in save icon in the toolbar.n in my form  i have sign button for initial form to send email to user group.After sign up i have click the save built icon to save the document

  • 01-27-2012 04:17 AM In reply to

    Re: How to write C# Code for custom print button?

    For my suggestion above to work, you need to save the form before viewing it in a Print Preview using the link above.

    Assuming, the form is now saved to the library. You now need to create a data connection within your form to retrieve the data from the library where you saved the form. Retrieve the columns from the library that will give you the filename (Probably 'Title'). Also, check 'Include data for the active form only' as you are creating the data connection

    For now, create a refresh button and add the necessary rules:

    1. Query your form library data connection

    2. Set MyFileNameField = concat(MyLibraryDataConnection.Title, ".xml")

    Once the form is saved and you hit the refresh button in your form, the file name field should have something like 'shahripusForm.xml' or whatever. If so, you can then use this field in your link instead of DocumentName

    One thing I should mention, I ended up reverting back to the built in Print Preview button because I had a problem the custom one. My problem was that if a user opened a previously saved form, made changes and then selected Print Preview without saving the form again, the print preview would not reflect the new changes. This was a deal breaker for me

    Nevertheless, in workflows I still find the link useful if I wanted to point someone at the print preview instead of the form itself.

    Now I need to get back to work! :)

Page 1 of 1 (14 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.