Facing Errors while opening .ost file

aabhi

New member
Joined
Nov 14, 2018
Messages
1
Location
United States
Programming Experience
1-3
I’m unable to open .ost file in C# code. I have written lines of code in C# language in Visual Studio 2015. After writing lines of code I’ve faced so many errors in code. I have used console command inside a function that executes scheduled task.

My lines of codes are-
Microsoft.Office.Interop.Outlook.Application objOutlookApplication = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.
NameSpace objNamespace = objOutlookApplication.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder objMAPIFolder = null;
try
{

objMAPIFolder = (MAPIFolder)objNamespace.OpenSharedFolder(@"\AppData\Local\Microsoft\Outlook\abc", null, null, null);
Folder objFolder = (Folder)objNamespace.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
string name = objFolder.FullFolderPath;
}

catch (StackOverflowException ex)
{
// MessageBox.Show(e.Message);
}


Error Message:

System.Runtime.InteropServices.COMException was unhandled
Message="Invalid shared folder."
Source="Microsoft Outlook"
ErrorCode=-2147352567
StackTrace:
at Microsoft.Office.Interop.Outlook.NameSpaceClass.OpenSharedFolder(String Path, Object Name, Object DownloadAttachments, Object UseTTL)
at WindowsApplication1.ReadOST.btnOSTRead_Click(Object sender, EventArgs e) in \WindowsApplication1\WindowsApplication1\ReadOST.cs:line 37
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WindowsApplication1.Program.Main() in \WindowsApplication1\WindowsApplication1\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

I have tried to search this error message on CSharpForums and found nothing.
http://www.csharpforums.net/forumdisplay.php/79-C-General-Discussion

Then I referred to C# forums and found few sources. Kindly refer these sources and provide which one easily fix my lines of code error.
https://fmforums.com/topic/103669-ost-file-in-c/
https://codepad.co/snippet/dyjIh4PQ
https://www.stellarinfo.com/convert-ost-to-pst.php
https://www.nopcommerce.com/boards/t/56083/how-to-open-ost-file-using-c-net.aspx

Which solution will fix the error?
 

percywilliamson

New member
Joined
Dec 4, 2018
Messages
2
Programming Experience
5-10
Could you please specify the error is on which line exactly?. I had faced a similar issue in past. You could try to excluding NULL values and see if this still persists. For reference check out :
 
Last edited by a moderator:
Top Bottom