In the following code, the second line throws an error that reads “Exception from HRESULT: 0x800A03EC”. I suspect I’m getting a null for FullName. Can someone tell me what I’m doing wrong?
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();
For context, this is an Excel 2010 add-in written in C# targeting .NET 4.0. The objective of the code is to save the document to a database.
Use
Globals.ThisAddIn.Application.ActiveWorkbook.FullName. From MSDNGlobals.ThisAddIn.Application.ThisWorkBookreturns the workbook where “Macro” is running. Since you don’t have a macro this will throw an exception.