1 Reply Latest reply on Nov 16, 2018 8:47 AM by Mario Zahren

    Try to open MS Outlook OST file in C#

    Claire Divas

      I’m asking here this question because I’m getting no responses on other several C# forums.

      I have a C# application in which I’m trying to open OST file. After initialization of all functions, file path, file name and root folder. During testing of C# application error occur. First time I have seen weird error. To resolve this weird error, I have changed the source code and restarted the application again. While starting the application, same error again occur.


      The code which I have used in C# is:


      Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();


      NameSpace outlookNs = app.GetNamespace("MAPI");

      // Add PST file (Outlook Data File) to Default Profile


      • outlookNs.AddStore(pstFilePath);


      MAPIFolder rootFolder = outlookNs.Stores[pstName].GetRootFolder();


      Folders subFolders = rootFolder.Folders;



      I have tried to search problem regarding OST file in C# over this forum but can’t find any question.



      After using Google, I have found few approaches. In these approaches lots of coding involved. Probably this may solve problem.







      Please suggest, which approach is better than other approaches.

        • Re: Try to open MS Outlook OST file in C#
          Mario Zahren

          What do you want to achieve with it?
          Do you want to write an email with outlook from your own account?


          using Outlook = Microsoft.Office.Interop.Outlook;
          bool notRunning = false;
          Outlook.MAPIFolder targetFolder = null;
          Outlook.Items folderItems = null;
          Outlook.MailItem mail = null;
          Outlook.MailItem oMsg = null;
          Outlook.NameSpace nameSpace = null;
              Outlook.Application oApp = null;
              // check if Outlook is running.
              if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
                  oApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
                  // if not, create a new Instance of Outlook and login with Default-Profile.
                  oApp = new Outlook.Application();
                  nameSpace = oApp.GetNamespace("MAPI");
                  targetFolder = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                  folderItems = targetFolder.Items;
                  mail = folderItems.Add(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
                  nameSpace.Logon("Outlook", "", Missing.Value, Missing.Value);
                  nameSpace = null;
                  notRunning = true;
              // string mailSender = oApp.Session.CurrentUser.Address;
              // string senderProfile = oApp.Session.CurrentProfileName;
              if (notRunning == true)
                  oMsg = mail;
                  oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
          catch (COMException exp)
              vault.GetErrorString(exp.ErrorCode, out string errorName, out string errorDesc);
              vault.MsgBox(0, errorDesc, EdmMBoxType.EdmMbt_OKOnly, errorName);
              this.SendMailOnError(m_vault, uebergabeWerteString1, errorName, errorDesc);