InfoPath Current Year with XPath

15. November 2011 13:43

While working on an InfoPath form I had need to identify both the current month and the current year, well InfoPath 2010 does not define such functions, it does however provide a today funcation.  You should know that the today() returns the current date in the format YYYY-MM-DD.  Knowing this we can substring out the year/month portion of the date like below.

substring(today(), 1, 4) 

Just a little snipet to help avoid using code behind.  Enjoy.

SharePoint Client Object Model

4. March 2011 23:55

Recently I have been tasked with migrating excel based spreadsheets to a SharePoint based intranet.  This means migrating a spread sheet to an InfoPath form.  This by itself is a very simple task, but the data from the current spread sheet is compiled monthly and used for reporting.  The current process is this, the data is entered into the sheet, then someone else copies that data into another sheet, then someone else copies that data in to an access database, then the database run VBA marcos and hopfully you end up with the new spread sheet that is an accurate report. The current process is driven by excel and people and there are 4 places for errors.  First the original data entry, second the monthly copy, third the entry into the database and finally in the macros (but atleast the macros are a regular error.)  We can eliminate 3 of these error sources by using infopath and SharePoint to inport the data into a database and then using SSRS to produce the report.  Step one, replace the first spread sheet with an InfoPath form and a SharePoint library.  InfoPath is XML based and easier to query that excel.  Once the base data is in an easy to query format (InfoPath XML in this case) you can then import it into a reporting database.  In my case I am using the SharePoint Object Model to query a SharePoint library and return a list of forms; however, I must use a CAML query to load the items...

Once the data is in a reporting database you can use SSRS to report it.  Right now you have the original data entry as a point of error, but if your nightly SharePoint Object Model app is unit tested you have killed to other sources of error, the copy and entry.  The final error is eliminated by the fact that you are not using Excel and macros to render your report, it can be done in SSRS with unit testing C# and SQL for data queries.

SharePoint/InfoPath and Visual Studio 2010

7. February 2011 22:31

In the past I have not always followed best practices in creating and deploying InfoPath forms to SharePoint.  This has caused me great pain and has caused me to under utilize some of the nicer features of SharePoint.  For example, when updating a form template, I have sometimes needed to relink every document in the library.  Very painful in any library larger than 100 documents.  So bad idea is deploying InfoPath forms to SharePoint from InfoPath, it doesn't handle content types and different servers well.  Bad idea number two, not using version control with my forms.  A users comes to me and it is easier to build a form, publish and forget it.

 

Enter Visual Studio and SharePoint 2010

I build a form in InfoPath designer, just like before, and save off the xsn file.  Now rather than rush in and deploy the form, take the time and create a SharePoint 2010 solution in Visual Studio.  To get started I add a new Content Type.  By associating your form to a content type gain a ton of searching and filter features for you users and some consistency if you need to write any server side code.  When defining your content type you still need to edit xml to add columns. To add a new field to you content type add a new FieldRef and make sure to use the node attribute, this will link the form's content to a SharePoint Field. Now we need to associate the content type to the form template you have created.  To do this we first should add a Module to the project.  In the module Add a File Element to your module.  The url of the file should be set in the following manner, Url="/Forms/{Name of Content Type}/{Name of Template}.xsn"  That will get you template deployed.  Make sure that you have added the template file into your solution.  Now we need to associated your template to your content type.  Todo this add a Document Tempate element and set the Path element to the name of your template (with the xsn.)  Now take your solution and added it into your source control system through Visual Studio.  You can deploy through Visual Studio, or through power shell.

About the author

John Moore is a C# and .NET developer for Associated Electric Coop (aeci.org) in Springfield Missouri, USA.  I am also a Mono and .NET linux developer in my free time.  I am the author of the banshee-ampache extension.  If you are interested in my work then please look at the extension's source. Please file a bug or contact me with any issues.  Finally a link to my Resume.