簡體   English   中英

如何使用C#和Office Interop獲取Office文檔的完整文件名?

[英]How do I get the full filename for an Office document using C# and Office Interop?

在下面的代碼中,第二行拋出一個錯誤,顯示“HRESULT異常:0x800A03EC”。 我懷疑我的FullName得到了null。 有人能告訴我我做錯了什么嗎?

        Foo.DataClasses1DataContext db = new Foo.DataClasses1DataContext();
        string ThisDocument = Globals.ThisAddIn.Application.ThisWorkbook.FullName;
        byte[] inputBuffer = System.IO.File.ReadAllBytes(ThisDocument);
        Foo.RFP_Document rfpDocument = new MediaDesk.RFP_Document();
        rfpDocument.DocumentName = "Foobar";
        rfpDocument.DocumentFile = new System.Data.Linq.Binary(inputBuffer);
        db.RFP_Documents.InsertOnSubmit(rfpDocument);
        db.SubmitChanges();

對於上下文,這是一個用C#編寫的Excel 2010加載項,用於.NET 4.0。 代碼的目標是將文檔保存到數據庫中。

使用Globals.ThisAddIn.Application.ActiveWorkbook.FullName 從MSDN Globals.ThisAddIn.Application.ThisWorkBook返回正在運行“宏”的工作簿。 由於您沒有宏,因此會拋出異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM