Auto-number InfoPath forms in a SharePoint form library

In this InfoPath demo video you will see how you can use a SharePoint event receiver on a SharePoint form library to automatically number InfoPath forms that are submitted to the SharePoint form library.

In recipe 99, you'll learn how to write C# code that can automatically number InfoPath forms that are submitted to a SharePoint form library.

Get more solutions from InfoPath 2010 Cookbook 3 which is available on Amazon.com
OR
Watch next video: Use an InfoPath form and SharePoint Designer workflow to send an email with attachments

InfoPath demo video transcript:

Here I'm in SharePoint 2010, and I've already published an InfoPath form template to a SharePoint form library called AutoNumberLib.

So if I add a new form, you'll see that initially the form does not have a name assigned to it, but when I submit the form, a SharePoint event handler will run on this form library, and rename the InfoPath form that I submitted to have a particular name plus a number. What the event handler also does is write that form name into the InfoPath form itself.

I can repeat the process and add a second form. When I submit it and then refresh the form library, you'll see that the form gets number 2 assigned to it.

What I can also try to do is simultaneously submit two forms to the same form library. I'm logged in on another PC as a different user, and what I'll try to do is submit a form on the other PC first and then come back here and submit this form. So I'll go ahead and submit the other form and then submit this one.

Once this one has been submitted, you'll see that two new forms have been added to the form library, and when I refresh, you'll see that John Doe submitted form 3, and Jane Doe, which is the user I'm logged in as, has submitted form 4.

If I delete previously submitted forms... so I'll delete 1 and 3, and then I'll add a new form. You'll see that the numbering does not restart at 1, but that it continues at the highest number. So if I refresh, you'll see that the form that I just submitted is this form; form 5.

The only time that the numbering would reset is if I deleted all of these forms, and then added a new form, you would see that the form would get number 1 assigned to it.

Related InfoPath Demo Videos:

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent of S.Y.M. Wong-A-Ton. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author, S.Y.M. Wong-A-Ton.

 
InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers