Search code examples
c#.netinfopathvsta

Print a different view as the current one in Infopath GUI, using C# in the VSTA environment


I'm developing a GUI for Infopath. I'm using Microsoft Visual Studio Tools for Applications with C# as developing language. I have two views in my project, one is the result of the other. I'm getting problem with print button (as PDF): I'm trying to print the resulting view (modified over the first) from the editing one. What I got until now is a code that prints the current view. How can I print the second one !

public void PrintBtn_Clicked(object sender, ClickedEventArgs e)
    {
         this.CurrentView.Export("TestFileName.pdf", ExportFormat.Pdf);
    }

Thanks. Best regards.


Solution

  • looks like the Export method is only available on a View object and unfortunately InfoPath des not expose a view collection for you. I think your best bet would probably be to switch to the view you want to print via

    ViewInfos.SwitchView("view name");
    

    Then you can do your call to export. Then finally you can switch back to the previous view if required...

    I would expect this to flick up the second view for the user for a moment while the export is taking place but I can't test it because I'm in an an airport :p