数字签署docx而无需使用C#打开文档

时间:2012-09-04 06:46:47

标签: c# digital-signature

我尝试了下面的代码,但是我没有打开它就没有签署文件。是否可以在不打开证书的情况下使用证书签署文档。

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

0 个答案:

没有答案