Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I open the merged .docx it is requesting the signatures that were added in the SignatureSet. The problem seems to be in the Selection.Paste() function, but I haven't figured out how to fix it. The sign date is also removed.

This is the function that saves and signs each file based on user input.
C#
// Save the file before adding signature.
oDoc.SaveAs2(saveFile);

                Word.Paragraph oPara3;
                oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                oPara3 = oDoc.Content.Paragraphs.Add(ref oRng);

                Word.Range p3 = oPara3.Range;
                p3.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                oPara3.Range.InsertParagraphAfter();
                oPara3.Range.Select();


                SignatureSet signatureSet = oDoc.Signatures;
                //Signature objSignature = signatureSet.Add();
                Signature signature = signatureSet.AddSignatureLine();
                signature.Setup.ShowSignDate = true;
                signature.Sign();
                
                oDoc.SaveAs2(saveFile);
                oDoc.Close();
                oWord.Quit();
                GC.Collect();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);


Loop through the checked items and merge into report.
C#
for (int i = 0; i < listView1.CheckedItems.Count; i++)
                {
                    string wPath = treeView1.SelectedNode.FullPath;
                    string checkedItems = listView1.CheckedItems[i].Text;
                    string getDoc = Path.Combine(wPath, checkedItems);

                    Word._Document copyFromDoc = mergeApp.Documents.Open(getDoc);
                    copyFromDoc.ActiveWindow.Selection.WholeStory();

                    copyFromDoc.ActiveWindow.Selection.Copy();

                    mergeDoc.ActiveWindow.Selection.Paste();

                    copyFromDoc.Close();

                }
Posted
Updated 21-May-15 4:17am
v2
Comments
Philippe Mori 21-May-15 12:20pm    
I would think that is done by design that way to ensure that tampered documents are detected. Otherwise, what would be the point of digital signature?
Woody Wright 21-May-15 12:36pm    
Yes, that's true. So, I should have phrased my question like so: Is there a way to 'Lock' or 'Embed' the Signature when merging.
Dave Kreskowiak 21-May-15 12:51pm    
No. It's that way BY DESIGN. You cannot modify a file after it's been signed. In other words, the signatures are dropped when the file is modified. The new file has to be signed again by the original person.

Do you know what a digital signature is for and how they work?

Woody Wright 21-May-15 13:07pm    
Do I know what a digital signature is for? Yes. Do I know how they work? I'm trying to learn. I was hoping that the copy-paste function wouldn't be treated as a modification to the document. I will take your answer to mean "It can't be done". Thanks for your time.
Dave Kreskowiak 21-May-15 14:05pm    
If you change one single character in the document, no matter how it's done, it invalidates the signatures.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900