none
Import PST file remotely to Outlook 2010 RRS feed

  • Question

  • Good day,

    I am trying to figure out how to import PST files automatically using c#. How can i make it work remotely too? I already did some research about it:

    http://msdn.microsoft.com/en-us/library/office/ff869071.aspx

    http://msdn.microsoft.com/en-us/library/office/ff184648.aspx

    private void EnumerateStores()
            {
                Microsoft.Office.Interop.Outlook.Stores stores = Application.Session.Stores;
                foreach (Outlook.Store store in stores)
                {
                    if (store.IsDataFileStore == true)
                    {
                        MessageBox.Show(String.Format("Store: "
                        + store.DisplayName
                        + "\n" + "File Path: "
                        + store.FilePath + "\n"));
                    }
                }
            }

    Saying the following: System.Windows.Forms.Application does not contain a definition for 'Session' is the exception i get.

    Many thanks

    • Edited by Trantium Wednesday, October 31, 2012 11:07 AM
    • Moved by Bob Shen Thursday, November 1, 2012 5:50 AM (From:Visual C# General)
    Wednesday, October 31, 2012 11:01 AM

Answers

  • Hi Trantium,

    I hope following code can help you.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Outlook.Application olApp = null;
                Process[] PS = Process.GetProcessesByName("OUTLOOK");
                if (PS.Length > 0)
                {
                    olApp = Marshal.GetActiveObject("Outlook.Application")
                        as Outlook.Application;
                }
                else
                {
                    olApp = new Outlook.Application();
                }
                if (olApp != null)
                {
                    string Path = string.Empty;
                    OpenFileDialog OFD = new OpenFileDialog();
                    OFD.Filter = "pst |*.pst";
                    OFD.ShowDialog();
                    Path = OFD.FileName;
                    Object StoreObject = Path;
                    olApp.Session.AddStore(StoreObject);
                }
            }
        }
    }

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, November 1, 2012 6:15 AM
    Moderator
  • Hi Trantium,

    As far as I know that the pst file you can add to Outlook is a archive file at all and the pst file which related to account will create via Outlook automate. And it seem we have no ability to handle this action.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, November 5, 2012 6:34 AM
    Moderator

All replies

  • Hi Trantium,

    I hope following code can help you.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Outlook.Application olApp = null;
                Process[] PS = Process.GetProcessesByName("OUTLOOK");
                if (PS.Length > 0)
                {
                    olApp = Marshal.GetActiveObject("Outlook.Application")
                        as Outlook.Application;
                }
                else
                {
                    olApp = new Outlook.Application();
                }
                if (olApp != null)
                {
                    string Path = string.Empty;
                    OpenFileDialog OFD = new OpenFileDialog();
                    OFD.Filter = "pst |*.pst";
                    OFD.ShowDialog();
                    Path = OFD.FileName;
                    Object StoreObject = Path;
                    olApp.Session.AddStore(StoreObject);
                }
            }
        }
    }

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, November 1, 2012 6:15 AM
    Moderator
  • Hi Trantium,

    I hope following code can help you.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Outlook.Application olApp = null;
                Process[] PS = Process.GetProcessesByName("OUTLOOK");
                if (PS.Length > 0)
                {
                    olApp = Marshal.GetActiveObject("Outlook.Application")
                        as Outlook.Application;
                }
                else
                {
                    olApp = new Outlook.Application();
                }
                if (olApp != null)
                {
                    string Path = string.Empty;
                    OpenFileDialog OFD = new OpenFileDialog();
                    OFD.Filter = "pst |*.pst";
                    OFD.ShowDialog();
                    Path = OFD.FileName;
                    Object StoreObject = Path;
                    olApp.Session.AddStore(StoreObject);
                }
            }
        }
    }

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thanks for helping me, but i have a question..

    How can i add pst files remotely to other accounts?

    Thursday, November 1, 2012 12:41 PM
  • Hi Trantium,

    As far as I know that the pst file you can add to Outlook is a archive file at all and the pst file which related to account will create via Outlook automate. And it seem we have no ability to handle this action.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, November 5, 2012 6:34 AM
    Moderator