Friday 15 January 2010

Dynamically Modifying the Submit Location of InfoPath Forms using SharePoint Forms Services using Code Behind

It is a well known fact (e.g. that SharePoint performance can decline significantly when there are more than 2000 items in a SharePoint "container"  (e.g. the root folder of a Document Library). To avoid this, you can store your documents in separate lists or you can store them in separate subfolders within your list.

On issue is that InfoPath 2007 doesn't support dynamic saving to subfolders out of the box (it only supports dynamic file names). You need to perform a code-based workaround to get it happening. In the code sample below, I dynamically submit to a folder location (ie a subfolder within a Document Library or List) based on the current date. All form submissions in this way are grouped by Year and Month (the client is not likely to have more than 2000 forms submitted in one month).

public void submitButton_Clicked(object sender, ClickedEventArgs e)
            ////Need to submit the form to a programatically determined subfolder location (based on the date)
            //Folder format is 2010_01_January (YYYY_MM_MMMMM)
            FileSubmitConnection submitConnection = (FileSubmitConnection)DataConnections["SharePoint Library Submit"];
            submitConnection.FolderUrl = string.Format("{0}/{1}_{2}_{3}",submitConnection.FolderUrl ,
                DateTime.Today.Year, DateTime.Today.Month.ToString("00"), 
            ////TODO: Need to create folder with SP Object Model to hold attachments as well before saving them there.


Erik said...


This is great. Can code be entered that specifies a folder based on form data selected. For example, if I have a drop-down list in my infopath form and I want option A to go to subfolder A of my document library, option B to go to subfolder B in my document library, etc...Is this possible?

mansuri.isteyaq said...

Hi I am searching for end user should select folder location or library location where the file should be stored. Do you have any idea how it is possible? kindly guide.

mansuri.isteyaq said...

Please consider this using infopath. Some pop up should be available with whole site folder hierarchy for user to choose location and infopath form should add that file to this selected folder location.

Unknown said...

Biztalk server online training - 21st Century Software Solutions
biztalk server online training, biztalk server training, biztalk server online training visakhapatnam, biztalk 2010 online training, microsoft biztalk online training, ...
Biztalk admin online training - 21st Century Software Solutions
biztalk admin online training, biztalk admin training, biztalk server online training, biztalk server training, biztalk admin course contents, biztalk admin enquiry, ...

Unknown said...

Great Job Nice Blog...
Biztalk Online Training Hyderabad

svrtechnologies said...

Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing...

online biztalk training