Showing posts with label Views. Show all posts
Showing posts with label Views. Show all posts

Saturday, January 26, 2013

Getting a specific list view as a data source in Infopath


1.       Create the view you intend to pull in SharePoint. Make sure to sort it and filter it the way you want it to appear in the drop down.
2.       Click on Settings->List Settings to get to the settings of the list you want to use.

3.       Scroll to the bottom where it shows views and click on the view that you want. This should be where you would edit the view.
4.       Go up to the URL and copy everything after List= (this is the GUID of the view).
5.       Place what you have in notepad.
6.        Replace %7B with { (this should be first part.
7.        Replace %7D with } (this should be the last part.
8.       Replace %2D with a –
9.       You should have something that looks like
{FCE658C5-54A5-4460-B9F4-6EE4CBF017D7}
Note:the numbers and letters are unique to your view but the formatting should be the same.
10.   Take the url of the site where the list resides and put it in front of the GUID
11.   Now you have the pieces to build your string. The format of the string is
<URL>/_vti_bin/owssvr.dll?Cmd=Display&List=<ListGUID>&View=<ViewGUID>&XMLDATA=TRUE
for example: 
http://site/_vti_bin/owssvr.dll?Cmd=Display&List={FCE658C5-54A5-4460-B9F4-6EE4CBF017D7}&View={B9BC3880-739B-4DA0-89A7-716775E755B7}&XMLDATA=TRUE
12.   You now have the string you need to create the data connection in Infopath.
13.   In Infopath you need to add a data connection.
14.   Create a new connection to receive data. Click OK.
15.   Choose XML document. Click OK.
16.   Paste the string you created in notepad into the Enter the location of the XML data file that you want to use as your data connection.
17.   Click next and okay until you are out of the wizard and you are ready to use your data source. If you are given a security prompt you can just click cancel.
18.   Note: everyone that uses the form must have read access (at least) to the list you are pulling from.

This article was taken from Michael Doyle from SharePoint Ninja

http://www.sharepointninja.com/Blog/Lists/Posts/Post.aspx?ID=13

Sunday, October 14, 2012

Save form data to a PDF file on a disk

Problem: You want to print some or all of the data from an InfoPath form to PDF.

You can create a print view that can be used specifically to print form data to PDF and then assign this view as the print view of another view that is used to fill out the form.

1 - Create a new InfoPath Filler form

2 - Create a new view and call it PrintToPDF

3 - Create custom fields, add those fields to both the default and the PrintToPDF view.

4 - Customize the PrintToPDF view and make sure that no borders for the controls appears. One way to do this is to use "Calculated Values" as much as possible instead of regular Text Boxes. Another way is to simply hide the borders under properties.

5 - Go back to the default view, click on properties and under the Print Settings tab select PrintToPDF in the drop-down under the Designate Print View section. Once this is done you have configured the default view to use PrintToPDF view as its print view.

6 - Add a button and under it's clicked event handler add the following code"

   Dim formName As String = CurrentView.Window.Caption
   CurrentView.Export("c:\temp\" & formName & ".pdf", ExportFormat.Pdf)

7 - Give the form template Full Trust. Save and build the project.

8 - Once you click on the button you will see that a PDF was created under the temp folder.

The Export() method is not available for InfoPath browser forms. For browser forms you can use a different technique that will be shown later that saves the form as a PDF in a SharePoint document library.

Switching between different views

Problem: You would like to press a button and have the form go to a different view

1 - Create "View 1" (Default) and "View 2" on the form template

2 - On "View 1"  add a button, set the ID of this button to "ChangeView" and change the label to "Change View".

3 - On the Clicked event handler of the button "ChangeView" add the following code

ViewInfos.SwitchView("View 2")

4 - Preview the form, you will notice that when you click the button "ChangeView" the form will switch view to "View 2".

Switch to show a specific view when a form opens

Problem: You have an InfoPath form that has two views and you want to be able to set the InfoPath form to start up with and show one of these two views.

You can use the SetDefaultView() method of the LoadingEventArgs object in the FormEvents_Loading() event handler of a form to switch to a particular view when the form opens.

1 - Add a new view called "View 2"

2 - Add the following code to the FormEvents_Loading() event handler

 e.SetDefaultView("View 2")

3 - Preview the form, when it opens View 2 will appear.

About Me

My photo
Toronto, Ontario, Canada
MBA, M.Sc. & MCP