Created
November 19, 2012 16:18
-
-
Save JDMcKinstry/4111571 to your computer and use it in GitHub Desktop.
Sharepoint2010: How to reset InfoPath Signatures in a C# Workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SPSecurity.RunWithElevatedPrivileges(delegate() | |
| { | |
| SPFile formFile = workflowProperties.Item.File; | |
| MemoryStream ms = new MemoryStream(formFile.OpenBinary()); | |
| XmlTextReader rdr = new XmlTextReader(ms); | |
| XmlDocument xmlDoc = new XmlDocument(); | |
| xmlDoc.Load(rdr); | |
| rdr.Close(); | |
| ms.Close(); | |
| XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable); | |
| // FYI, this was the schema I found for mine, for whatever reason yours maybe different, but it should be located as an attribute of your Document | |
| String schemaUri = xmlDoc.DocumentElement.GetAttributeNode("xmlns:my") != null ? xmlDoc.DocumentElement.GetAttributeNode("xmlns:my").Value : "http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-09-04T20:19:31"; | |
| nsm.AddNamespace("my", schemaUri); | |
| XmlNode nodeSignatureCollection = xmlDoc.DocumentElement.SelectSingleNode("my:signatures1", nsm); | |
| if (nodeSignatureCollection != null) | |
| { | |
| if (nodeSignatureCollection.HasChildNodes) | |
| { | |
| foreach (XmlNode nodeSignature in nodeSignatureCollection.ChildNodes) | |
| { | |
| // HERE IT IS!!! | |
| if (nodeSignature.HasChildNodes && !nodeSignature.IsReadOnly) nodeSignature.RemoveAll(); | |
| } | |
| } | |
| } | |
| byte[] xmlData = System.Text.Encoding.UTF8.GetBytes(xmlDoc.OuterXml); | |
| formFile.SaveBinary(xmlData); | |
| formFile.Update(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment