Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is it possible to change the content of a field in a InfoPath form from a workflow in SharePoint. I have tried working with the "Update List Item" action but have been unable to to find a direct way of doing this.

share|improve this question
add comment

2 Answers 2

You can always download the xml of the InfoPath form using SPFile and have the workflow modify the contents of the xml file, thus modifying the item. To download the item try something like this

            using (var site = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    #region download an intake form and parse into xml

                    //this code lets you download an intake form, parse its xml and save it 
                    SPFile file = web.GetFile(urlOfFile);
                    var sr = new StreamReader(file.OpenBinaryStream());
                    XDocument xdoc = XDocument.Parse(sr.ReadToEnd());
                    sr.Close();
                    return xdoc;

                    #endregion download ...
                }
            }

Then once it's download, grab the XElement of the field you want to modify, and change the value. Then convert the XDocument back to a Stream and save it back to the SPFile using SPFile.SaveBinary() method then use SPFile.Update() to save your changes to the SPFile object.

share|improve this answer
add comment

Easiest way to do this is just promote the column from your InfoPath form so that SharePoint can see it (make sure you allow editing) then you can modify just like any other SharePoint list item (and no need to use any managed code).

I like Meyer's answer though if you are worried about users entering bad values from a datasheet or something and can deploy custom code in your environment.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.