简体   繁体   English

如何在Sharepoint 2010中的c#工作流程中重置InfoPath表单的数字签名?

[英]How to reset digital signature of an InfoPath form during c# workflow in Sharepoint 2010?

As the question says, I have an InfoPath form running on SP2010 using ac# workflow upon submission. 正如问题所说,我在提交时使用ac#工作流在SP2010上运行了一个InfoPath表单。 If the form is rejected during workflow, then I need to reset it. 如果表单在工作流程中被拒绝,那么我需要重置它。 I have everything under control, EXCEPT how to reset digital signatures to null, nill, nada, nothing, non-extant! 我掌握了一切,除了如何将数字签名重置为null,nill,nada,没有,非现存! Any ideas? 有任何想法吗? I'm looking at Google now, but at current, I'm not even sure of an om for digital signatures? 我现在正在看谷歌,但就目前而言,我甚至不确定是否有数字签名?

Wow, i notice this question suddenly gaining alot of pop with bounty almost gone. 哇,我注意到这个问题突然获得了很多流行音乐,奖金几乎消失了。 Just putting it out there, I did not intend to not bounty someone, but i needed the answer earlier this week (2nd week Nov 2012) and thus i searched and played and teetered with code as much as possible till i ended up finding my own answer before anyone else answered me. 只是把它放在那里,我不打算不给别人,但我本周早些时候需要答案(2012年11月第2周),因此我尽可能地搜索和播放代码,直到我找到了自己的代码。在别人回答我之前回答。 However, for future reference, if someone gives a better answer, i'll gladly come back and rep them. 但是,为了将来参考,如果有人给出了更好的答案,我很乐意回来并代表他们。 Thank you all for the support and I really hope my answer is as useful to another as it was to me. 谢谢大家的支持,我真的希望我的回答对我来说同样有用。

NOW Bloggered && Gisted May no one ever again have to search as hard as I did for this answer, :P 现在 Bloggered && Gisted 可能再没有人像我对这个答案那样努力搜索,:P

¡¡¡ I FOUNDMYFRIGGIN ' ANSWER ! 我发现了一个AN AN AN AN AN AN AN AN AN AN!!!!!!! ! !

¡¡¡ And it works from the workflow !!! 从工作流程开始工作!!!

Through much trial and tribulation I was finally able to come up with a solution. 通过大量的试炼和磨难,我终于能够找到解决方案。 It involves a few steps. 它涉及几个步骤。 One, elevate security! 一,提升安全性! Otherwise, non-admin users will cause the workflow to error. 否则,非管理员用户将导致工作流程出错。 Seems like it should work this way, but ... Secondly, get the right schema! 看起来它应该以这种方式工作,但是......其次,获得正确的架构! It took me a while to find mine, i forgot the exact steps, but, it's not hard to find. 我花了一段时间找到我的, 我忘记了确切的步骤,但是,这并不难找到。 UPDATED: Can be found as an attribute of xmlDoc.Document, see updated code Step through (debug) your workflow, without the namespace/schema and highlight your document when it gets to it. UPDATED: Can be found as an attribute of xmlDoc.Document, see updated code逐步(调试)您的工作流,没有命名空间/架构,并在文档到达时突出显示您的文档。 One of the properties is an url that is the schema link. 其中一个属性是作为架构链接的URL。 Anyway, you wanna see the solution!? 无论如何,你想看到解决方案!? Do ya? 你呢? Look down! 向下看!

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);
    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();
});

Keep in mind, this setup is for going through multiple signatures. 请记住,此设置用于通过多个签名。 Although I doubt anything would change if there was only one signature. 虽然我怀疑如果只有一个签名会有任何改变。

Any suggestions on making this sweeter and smaller are accepted, however, I must request an explanation. 关于使这种更甜更小的建议被接受,但是,我必须要求解释。 Honestly, I barely understand what is going on here! 老实说,我几乎不明白这里发生了什么!

The following answer only HALF works. 以下答案仅适用于HALF。 It is left here for instructional purpose. 它留在这里用于教学目的。 ( Full working answer can be found here. ) It works for admin users, but nothing less. 完整的工作答案可以在这里找到。 )它适用于管理员用户,但没有更少。 It also only works from the InfoPath form behind code. 它也只能在代码后面的InfoPath表单中使用。 NOT from the workflow. 不是来自工作流程。 Adding elevated privlage seems to have 0 effect 增加高架权利似乎有0效果

I'm leaving this answer up here along with my other so that someone may learn from both examples or possibly even instruct others (including myself) via comments and what not on why one way may be better than the other. 我将这个答案与我的其他人一起留在这里,以便有人可以从这两个例子中学习,或者甚至可以通过评论指导其他人(包括我自己),而不是为什么一种方式可能比另一方更好。 At this point, I really don't care to explain anymore as I really don't care to see any of this code ever again! 在这一点上,我真的不在乎解释,因为我真的不在乎再看到这个代码! LoL! 大声笑!

public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
    string[] actionFields = new string[] { "/my:myFields/my:.../my:...", "/my:myFields/my:.../my:...", etc... };
    for (int i = 0; i < actionFields.Length; i++)
    {
        String field = actionFields[i];
        XPathNavigator node = this.MainDataSource.CreateNavigator().SelectSingleNode(field, this.NamespaceManager);
        if (node.Value.ToLower() == "reject")
        {
            XPathNavigator sigNode = this.MainDataSource.CreateNavigator();
            if (this.Signed) //then unsign it
            {
                for (int ii = 2; ii <= 13; ii++)
                {
                    try
                    {
                        XPathNavigator xSignedSection = sigNode.SelectSingleNode(String.Format("my:myFields/my:signatures1/my:signatures{0}", ii), this.NamespaceManager);
                        if (xSignedSection.HasChildren)
                        {
                            xSignedSection.MoveToChild(XPathNodeType.Element); xSignedSection.DeleteSelf();
                        };
                    }
                    catch (Exception ex) { };
                };
            };
        };
    };
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM