473,394 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Switching Outlook Profiles

Hi ,

I am developing a windows application using C#. In that I want to display all the outlook profiles in a listbox and on selecting one, The folder structure should be displayed on a treeview control.

I can display all the profiles in the listbox and on its changedindex event I am calling the function to load all outlook folders(and add that to the treeview).

When i run the application first time it is working properly , but when i select the other profile it loads the folder structure of firstprofile it self...

Expand|Select|Wrap|Line Numbers
  1.   public void LoadOutlookFolders(string MSOprofile)
  2.         {
  3.             try
  4.             {
  5.                 Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
  6.                 Outlook.NameSpace ns = app.GetNamespace("MAPI");
  7.  
  8.                 ns.Logon(MSOprofile, _missing, false, true);
  9.  
  10.                 TreeNode rootnode = treeFolders.Nodes.Add("MS Outlook");
  11.                 rootnode.Tag = -1;
  12.  
  13.                 for (int i = 1; i <= ns.Folders.Count; i++)
  14.                 {
  15.                     Outlook.MAPIFolder cFolder = ns.Folders[i];
  16.                     TreeNode FLevelNode = rootnode.Nodes.Add(cFolder.Name);
  17.  
  18.                     FolderParam flParam = new FolderParam();
  19.                     flParam.Name = cFolder.Name;
  20.                     flParam.EntryId = cFolder.EntryID;
  21.                     flParam.StoreId = cFolder.StoreID;
  22.                     flParam.Type = "Outlook";
  23.                     flParam.DefaultMessageClass = cFolder.DefaultMessageClass;
  24.                     FLevelNode.Tag = flParam;
  25.  
  26.                     for (int j = 1; j <= cFolder.Folders.Count; j++)
  27.                     {
  28.                         if (cFolder.Folders[j].DefaultMessageClass == "IPM.Note" || cFolder.Folders[j].DefaultMessageClass == "IPM.Contact")//Add only the messages and contact folders(excluding calendar,notes,....
  29.                         {
  30.                             TreeNode sLevelNode = FLevelNode.Nodes.Add(cFolder.Folders[j].Name);
  31.  
  32.  
  33.                             displayOutlook(cFolder.Folders[j], sLevelNode);
  34.  
  35.                             FolderParam fldrParam = new FolderParam();
  36.  
  37.                             fldrParam.Name = cFolder.Folders[j].Name;
  38.                             fldrParam.EntryId = cFolder.Folders[j].EntryID;
  39.                             fldrParam.StoreId = cFolder.Folders[j].StoreID;
  40.                             fldrParam.Type = "Outlook";
  41.                             fldrParam.DefaultMessageClass = cFolder.Folders[j].DefaultMessageClass;
  42.  
  43.                             sLevelNode.Tag = fldrParam;
  44.                             cFolder.Folders[j].Items.Session.Logoff();
  45.                             cFolder.Folders[j].Application.Session.Logoff();
  46.                             cFolder.Folders[j].Session.Logoff();
  47.                         }
  48.                     }
  49.                     ns.Folders[i].Session.Logoff();
  50.                     ns.Folders[i].Items.Session.Logoff();
  51.                     ns.Folders[i].Application.Session.Logoff();
  52.                     cFolder.Items.Session.Logoff();
  53.                     cFolder.Application.Session.Logoff();
  54.  
  55.                     cFolder.Session.Logoff();
  56.  
  57.                 }
  58.                 if (rootnode != null && rootnode.FirstNode != null)
  59.                 {
  60.                     rootnode.ExpandAll();
  61.                 }
  62.  
  63.                 ns.DefaultStore.Session.Logoff();
  64.  
  65.                 ns.CurrentUser.Session.Logoff();
  66.  
  67.  
  68.                 ns.Accounts.Session.Logoff();
  69.                 ns.Session.Logoff();
  70.                 ns.Logoff();
  71.                 app.Session.Logoff();
  72.  
  73.                 app.Quit();
  74.                 insertOutlookProfiles();
  75.  
  76.             }
  77.             catch (Exception ex)
  78.             {
  79.                 MessageBox.Show(ex.Message);
  80.             }
  81.         }
  82.         public void displayOutlook(Outlook.MAPIFolder folder, TreeNode rootnode)
  83.         {
  84.             for (int j = 1; j <= folder.Folders.Count; j++)
  85.             {
  86.                 TreeNode node = rootnode.Nodes.Add(folder.Folders[j].Name);
  87.                 FolderParam flparam = new FolderParam();
  88.  
  89.                 flparam.Name = folder.Folders[j].Name;
  90.                 flparam.EntryId = folder.Folders[j].EntryID;
  91.                 flparam.StoreId = folder.Folders[j].StoreID;
  92.                 flparam.Type = "Outlook";
  93.                 flparam.DefaultMessageClass = folder.Folders[j].DefaultMessageClass;
  94.                 node.Tag = flparam;
  95.                 if (folder.Folders[j].Folders.Count > 0)
  96.                 {
  97.                     displayOutlook(folder.Folders[j], node);
  98.                     folder.Folders[j].Items.Session.Logoff();
  99.                     folder.Folders[j].Application.Session.Logoff();
  100.                     folder.Folders[j].Session.Logoff();
  101.                 }
  102.                 else
  103.                 {
  104.                     folder.Folders[j].Items.Session.Logoff();
  105.                     folder.Folders[j].Application.Session.Logoff();
  106.                     folder.Folders[j].Session.Logoff();
  107.                 }
  108.  
  109.             }
  110.  
  111.             folder.Items.Session.Logoff();
  112.             folder.Application.Session.Logoff();
  113.             folder.Session.Logoff();
  114.  
  115.         }

Can any one help me in this Or Is there is any other way to achieve this?

Thanking you in advance,
Jaz
Oct 2 '07 #1
0 1589

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: srinivas | last post by:
Hi, i'm trying to retreive the appointments from different profiles of outlook. My outlook has 3 profiles created.('Sample1','Sample2','Sample3') my form contains 3 buttons.each one for each...
9
by: Srinivas | last post by:
hi all how to access the outlook user profiles through VB.net any help.... thanks in advanc Srinivas
3
by: Paul | last post by:
Hello, I am trying to set up a program that will email me when a process has been completed by a user. The user uses a program that moves some files, after these files are moved I want the...
5
by: Mike P | last post by:
I am trying to get at different users inboxes programmatically (see code below). It works fine, except for the fact that the logon line seems to always logon to my local account rather than...
2
by: =?Utf-8?B?UmFscGggSQ==?= | last post by:
OK, Dell inspirion 9300 - 100 gb hd partitioned into 3 drives C: OS 10 gb D: Programs 20 gb E: Data 70 GB Page Files 0 on C: 4092 on D: 3070 on E:
1
by: jazeelkm | last post by:
Hi all, I am developing an windows application using C#. In that application I have to extract all the email ids stored in the contact folder of the outlook... Now I can extract the details using...
0
by: gidiop | last post by:
I need to retrieve the outlook's profiles (using C#). I thought that this could be done via the Outlook object model, but I can't find the way doing it. Any help will be appreciated, Oren.
0
by: awrightus | last post by:
I want to develop an interface to create, edit, and delete Outlook profiles. The system I want to do this on will Have Outlook 2003 on it. I can use much of the Office Interop stuff to...
1
by: =?Utf-8?B?RWQgUy4=?= | last post by:
I have three Profiles set-up in Outlook (w/XP Pro). In the past, to go from one account to another, all I had to do was X out at the upper right which would take me back to the Profile sign in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.