3

I tried this the code below but I failed to sign a document without opening it. Is it possible to sign a document with a certificate without opening it.

object TempFilePath = TemporaryFolder + FileTempName;
object Visible = false;
object readonlyfile = false;

try
{
    object missing = System.Reflection.Missing.Value;
    Microsoft.Office.Interop.Word.ApplicationClass wordapp = new
    Microsoft.Office.Interop.Word.ApplicationClass();
    Microsoft.Office.Interop.Word.Document wordDocument = wordapp.Documents.Open(ref
TempFilePath, ref missing,
    ref readonlyfile, ref missing, ref missing,
    ref missing, ref missing, ref missing,
    ref missing, ref missing, ref missing,
    ref Visible, ref missing, ref missing,
    ref missing, ref missing);

    //    wordDocument.Activate();

    //  object sigID = "{00000000-0000-0000-0000-000000000000}";

    //   wordDocument.ActiveWindow.Application.ActiveDocument.Signatures.AddSignatureLine(sigID);
    //   wordDocument.ActiveWindow.Application.ActiveDocument.Signatures.Commit();
    SignatureSet signatureSet = wordDocument.Signatures;
    Signature objSignature = signatureSet.Add();


    if (objSignature == null)
    {
        DocumentNotSigned(item);
        return false;
    }
    else
    {
        signatureSet.Commit();
        object saveChanges = true;
        wordDocument.Close(ref saveChanges, ref missing, ref missing);
        wordapp.Quit(ref missing, ref missing, ref missing);
        return true;
    }
Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105
  • 2
    What do you mean by "not opening it"? That code seems to open a word document. – Mizipzor Sep 04 '12 at 07:22
  • yeh,actually it does,may be i need some other code to do that, many solutions i found obliges the user to open the document to sign it,what i intend to do is enable the user to sign any document on web application wihout even opening that document. – micro apples in motion Sep 04 '12 at 07:53
  • seems strange to have a user to sign a document that they don't read. Why even have them sign, as the point of the signature is that they agree to the document. – Peter Mendez Feb 15 '17 at 03:56

0 Answers0