c# - How to identify the Excel custom property is exists or not? -


using excel = microsoft.office.interop.excel; 

i using method set excel custom property if property exists throws exception, , how can update property if exists

public excel.workbook workbk; application _excelapp;  public void setdocumentproperty(string propertyname, string propertyvalue) {     try     {         _excelapp = new application();         workbk = _excelapp.workbooks.open(@"c:\12345.xlsx",         type.missing, type.missing, type.missing, type.missing,         type.missing, type.missing, type.missing, type.missing,         type.missing, type.missing, type.missing, type.missing,         type.missing, type.missing);          object odoccustomprops = workbk.customdocumentproperties;         type typedoccustomprops = odoccustomprops.gettype();           object[] oargs = {propertyname,false,          msodocproperties.msopropertytypestring,          propertyvalue};           typedoccustomprops.invokemember("add", bindingflags.default |                                        bindingflags.invokemethod, null,                                        odoccustomprops, oargs);          workbk.save();     }         {          workbk.close(false, @"c:\12345.xlsx", null);          marshal.releasecomobject(workbk);     } } 

        string [] files = system.io.directory.getfiles(directory); 

u can use server mappath if u puting excel file in u project string[] files = system.io.directory.getfiles(server.mappath("~\upload"));

this line give u files exist in directory way u can check if file exist without getting exception


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -