Skip to content

Instantly share code, notes, and snippets.

@JDMcKinstry
Created November 19, 2012 16:18
Show Gist options
  • Select an option

  • Save JDMcKinstry/4111571 to your computer and use it in GitHub Desktop.

Select an option

Save JDMcKinstry/4111571 to your computer and use it in GitHub Desktop.
Sharepoint2010: How to reset InfoPath Signatures in a C# Workflow
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