c# - How to get records of email and user information from outlook 2007 pst file? -


i have code says instant of application not created

when excute code show output: file "@"c:\users\toseef abbasi\appdata \local\microsoft\outlook" not valid outlook personal folder file<.pst> outlook failed add personal store session

using system;  using system.collections.generic;  using microsoft.office.interop.outlook;  namespace pstreader {   class program   {      static void main()     {         try          {             ienumerable<mailitem> mailitems = readpst(@"c:\users\toseef abbasi\appdata               \local\microsoft\outlook", "outltoseefabbasi@hotmail.com-0000000b");              foreach (mailitem mailitem in mailitems)             {                  console.writeline(mailitem.sendername + " - " + mailitem.subject);             }          }          catch (system.exception ex)         {             console.writeline(ex.message);         }         console.readline();     }      private static ienumerable<mailitem> readpst(string pstfilepath, string pstname)     {         list<mailitem> mailitems = new list<mailitem>();          application app = new application();          namespace outlookns = app.getnamespace("mapi");          // add pst file (outlook data file) default profile          outlookns.addstore(pstfilepath);          mapifolder rootfolder = outlookns.stores[pstname].getrootfolder();          // traverse through folders in pst file          // todo: not recursive, refactor          folders subfolders = rootfolder.folders;          foreach (folder folder in subfolders)         {             items items = folder.items;              foreach (object item in items)             {                 if (item mailitem)                 {                     mailitem mailitem = item mailitem;                      mailitems.add(mailitem);                 }             }         }         // remove pst file default profile          outlookns.removestore(rootfolder);          return mailitems;     } } } 

in line below point folder , not actual file.

ienumerable<mailitem> mailitems = readpst(@"c:\users\toseef abbasi\appdata               \local\microsoft\outlook", "outltoseefabbasi@hotmail.com-0000000b"); 

shoud below pstname.pst actual pst file.

ienumerable<mailitem> mailitems = readpst(@"c:\users\toseef abbasi\appdata               \local\microsoft\outlook\pstname.pst", "outltoseefabbasi@hotmail.com-0000000b");