c# - xml load after exporting excel file failed -


i have c# application following features:

  • read password config file.
  • export excel file.

when read password @ fist: it's ok. once export excel file, can't no more read password config file. following instruction fail.

xmldoc.load("cfg.xml"); 

this issue appear on windows xp. on windows 7 it's ok.

the code reading password config file:

private void ok_click(object sender, eventargs e)         {             try             {                 // check password                 xmldocument xmldoc = new xmldocument();                 xmldoc.load("cfg.xml");                 xmlnode node = xmldoc.selectsinglenode("config/managerpw");                  if (node != null)                 {                     string mangerpw = node.attributes[0].value;                      pccrypto pwcrypto = new pccrypto();                     if (pwcrypto.verifymd5(this.password.text, mangerpw) == true)                     {                         iscorrectpassword = true;                         this.dispose();                     }                     else                     {                         messagebox.show("incorrect password!", "pw authentication", messageboxbuttons.ok,                            messageboxicon.error);                         this.password.text = "";                     }                 }                 else                 {                     messagebox.show("you tried perform unauthorized operation!", "pw authentication", messageboxbuttons.ok,                                messageboxicon.error);                     this.password.text = "";                 }             }             catch             {                 messagebox.show("error in loading configuration file", "configuration error", messageboxbuttons.ok,                                messageboxicon.error);                 this.dispose();              }          } 

the code of exporting excel file

public bool exporttoexcel(string path) {     bool bret = true;     int columnsnum = resultlist.columns.count - 1;     int rowsnum = resultlist.items.count;     object[,] array = new object[rowsnum + 1, columnsnum];      //change current system time     system.threading.thread.currentthread.currentculture = system.globalization.cultureinfo.createspecificculture("en-us");      excel.application xlapp = new excel.applicationclass();     excel.workbooks xlworkbooks = xlapp.workbooks;     excel.workbook xlworkbook = xlworkbooks.add(type.missing);     excel.sheets xlworksheets = xlworkbook.sheets;     excel.worksheet xlworksheet = (excel.worksheet)xlworksheets[1];      //disable alerts     xlapp.displayalerts = false;      //add header array                 (int = 0; < columnsnum; i++)     {         array[0, i] = resultlist.columns[i + 1].text;     }      //add listview data array     (int r = 0; r < rowsnum; r++)     {         (int c = 0; c < columnsnum; c++)         {             this.invoke(new methodinvoker(delegate             {                 array[r + 1, c] = resultlist.items[r].subitems[c+1].text;             }));         }     }      //save array data excel     excel.range c1 = (excel.range)xlworksheet.cells[1, 1];     excel.range c2 = (excel.range)xlworksheet.cells[rowsnum + 1, columnsnum];     excel.range xlrange = xlworksheet.get_range(c1, c2);     xlrange.borders.linestyle = excel.xllinestyle.xlcontinuous;            xlrange.entirecolumn.numberformat = "@";     xlrange.value2 = array;     xlrange.entirecolumn.autofit();      //add header color     xlworksheet.get_range("a1", "i1").interior.color = colortranslator.toole(color.aquamarine);      //save excel file     try     {         xlworkbook.saveas(@path, excel.xlfileformat.xlworkbooknormal, type.missing, type.missing, type.missing, type.missing, excel.xlsaveasaccessmode.xlexclusive, type.missing, type.missing, type.missing, type.missing, type.missing);         xlworkbook.close(true, type.missing, type.missing);     }     catch     {         bret = false;     }      xlworkbooks.close();     xlapp.application.quit();     xlapp.quit();     releaseobject(c1);     releaseobject(c2);     releaseobject(xlrange);     releaseobject(xlworksheet);     releaseobject(xlworksheets);     releaseobject(xlworkbook);     releaseobject(xlworkbooks);     releaseobject(xlapp);      return bret; } 

try specifying full path in

xmldoc.load("cfg.xml");  

e.g.

xmldoc.load(@"c:\myfolder\cfg.xml");  

the current folder being changed when export excel.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -