Asp.net 使用c在ms word中添加CustomDocumentProperties时出现未指定错误

Asp.net 使用c在ms word中添加CustomDocumentProperties时出现未指定错误,asp.net,Asp.net,我想使用c将CustomDocumentProperties添加到现有的MS Word docx文件中。 我可以打开文件,但当我要添加CustomDocumentProperties时,它会给我 以下是例外 {来自HRESULT:0x80004005 E_FAIL的未指定错误异常} 还有一件事,当我尝试初始化一个新的doc对象时,它没有给我任何错误。 下面是我使用过的代码。如果我在这里犯了什么错误,请帮忙 object type = Type.Missing; Word.Application

我想使用c将CustomDocumentProperties添加到现有的MS Word docx文件中。 我可以打开文件,但当我要添加CustomDocumentProperties时,它会给我 以下是例外

{来自HRESULT:0x80004005 E_FAIL的未指定错误异常}

还有一件事,当我尝试初始化一个新的doc对象时,它没有给我任何错误。 下面是我使用过的代码。如果我在这里犯了什么错误,请帮忙

object type = Type.Missing;
Word.Application word;
Word._Document doc;
Word._Document doc1;
string filePath = "D:\\abc1.docx";
string targetFileName = "D:\\abc1.docx";

 protected void Page_Load(object sender, EventArgs e)
{
    word = new Word.Application();
    word.Visible = false;

    doc1 = word.Documents.Open(filePath, false);
    SetDocumentProperty1("Subject", "Whitepaper");
    GetDocumentProperty1("Subject", MsoDocProperties.msoPropertyTypeString);
    doc1.SaveAs(targetFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault);

    doc1.Close(false);
    System.Runtime.InteropServices.Marshal.ReleaseComObject(doc1);
}
   public void SetDocumentProperty1(string propertyName, string propertyValue)
{
    object oDocCustomProps = doc1.CustomDocumentProperties;
    Type typeDocCustomProps = oDocCustomProps.GetType();

    object[] oArgs = {propertyName,false,
             MsoDocProperties.msoPropertyTypeString,
             propertyValue};

    typeDocCustomProps.InvokeMember("Add", BindingFlags.Default |
                               BindingFlags.InvokeMethod, null,
                               oDocCustomProps, oArgs);



}
private object GetDocumentProperty1(string propertyName, MsoDocProperties type)
{
    object returnVal = null;

    object oDocCustomProps = doc1.CustomDocumentProperties;
    Type typeDocCustomProps = oDocCustomProps.GetType();


    object returned = typeDocCustomProps.InvokeMember("Item",
                                BindingFlags.Default |
                               BindingFlags.GetProperty, null,
                               oDocCustomProps, new object[] { propertyName });

    Type typeDocAuthorProp = returned.GetType();
    returnVal = typeDocAuthorProp.InvokeMember("Value",
                               BindingFlags.Default |
                               BindingFlags.GetProperty,
                               null, returned,
                               new object[] { }).ToString();

    return returnVal;
}