A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Friday, June 16, 2006

Manipulating SharePoint list's metadata from inside InfoPath

Yes, this is possible. You can manipulate SharePoint's list metadata from inside InfoPath. You must have InfoPath toolkit installed. See following post for reference:

/ssa/archive/2006/06/02/8029.aspx

You can get/set values in SharePoint list. Recently, I was working on a workflow solution that involved both SharePoint and InfoPath. Till now, all the workflow solutions that I developed used SharePoint as the main tool and workflow was built into SharePoint but this time, the requirement was a bit different. We wanted to build the workflow solution directly in InfoPath form and part of this requirement was to set a property's value in document library directly from InfoPath form. "Approval Status" field in form library can contain one of the following values:

1. Approved
2. Rejected
3. Pending

Depending on your form's requirements, you can set the value of "Approval Status" field directly from InfoPath. Here is the code:

SPWeb mySite = new SPSite("http://yourportal/sites/HR/HRForms/Forms/mod-view.aspx").OpenWeb();
SPFolder myFolder = mySite.GetFolder("HRForms");
SPFileCollection myFiles = myFolder.Files;
try
{
foreach (SPFile fyle in myFiles)
{
fyle.Item.ModerationInformation.Status = Microsoft.SharePoint.SPModerationStatusType.Pending;
fyle.Item.Update();
}
}


Code Explanation:

Open your site using OpenWeb() method. In the code above, first line opens a site called "HR". "HR" site has a folder named "HRForms" and this folder contains all forms. In the for-each loop, we are setting each file's status to "Pending". It is important to call the Update() method in order to apply the changes.

Add a reference to Microsoft.SharePoint (Microsoft.SharePoint.dll) and add following namespaces in the code:

using Microsoft.SharePoint;
using System.Collections;

-SSA

No comments:

Post a Comment