Solved

Access Outlook Public Calendar Folders

Posted on 2001-07-24
6
774 Views
Last Modified: 2010-04-06
I am trying to get calendar items from public folders in Exchange. I have gotten some code to work for the default calendar in Outlook, but could not figure out how to get the public folder items. I searched all over the internet and couldn't find the answer.  Sample code would be helpful, but not required.

I previously asked this question, and "smurff" said:

--------------------------------
The only thing I have is a VB code example of interfacing with the calender public folders in exchange.


You can add appointments to a user's personal calendar folder and to a public folder.

To add an appointment to a folder

Create an Appointment object.
Set the properties of the appointment. A StartTime is required.
Save the appointment to the designated folder by using the Appointment object's IDataSource Interface.
The following example shows how to create an appointment and then save it to a specified folder:

Visual Basic
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Exchange 2000 Library
Function CreateAppointment(StartTime As Date, _
                           EndTime As Date, _
                           Subject As String, _
                           Location As String, _
                           TextBody As String, _
                           iMbx As IMailbox) As Appointment

   Dim iAppt       As New Appointment
   Dim Conn        As New ADODB.Connection
   Conn.Provider = "ExOLEDB.DataSource"
   
   'Set the appointment properties
   With iAppt
       .StartTime = StartTime
       .EndTime = EndTime
       .Subject = Subject
       .Location = Location
       .TextBody = TextBody
       'Save the appointment
       Conn.Open iMbx.BaseFolder
       .DataSource.SaveToContainer iMbx.Calendar, Conn
   End With
   
   Set CreateAppointment = iAppt
End Function

sorry i dont have a delphi one. Maybe someone could convert for you?
regards
Smurff
--------------------------------

If you can convert that to Delphi, I'll give you and Smurff points.
0
Comment
Question by:NelsonR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 2

Expert Comment

by:SChertkov
ID: 6317443
Try following code

var
  Folder, objSession, Messages, Msg: OleVariant;
begin
  objSession := CreateOleObject('MAPI.Session');
  objSession.Logon;
  // List calendar folder
  Folder := objSession.GetDefaultFolder(0); // CdoDefaultFolderCalendar
  Messages := Folder.Messages;
  Msg := Messages.GetFirst;
  while not VarIsEmpty(Msg) do
    begin
      ListBox1.Items.Add(Msg.Subject);
      Msg := Messages.GetNext;
    end;
  // Add new item
  Msg := Folder.Messages.Add;
  Msg.Subject := 'Hello !';
  Msg.StartTime := Now;
  Msg.EndTime := Now + 1;
  Msg.Update;
  objSession.LogOff;
0
 
LVL 2

Expert Comment

by:SChertkov
ID: 6317457
See MSDN CDO 1.2.1 (Messaging and collaboration Services)
for details
0
 

Author Comment

by:NelsonR
ID: 6317546
Note what I said:
-----
I am trying to get calendar items from public folders in Exchange. I have gotten some code to work for
the default calendar in Outlook, but could not figure out how to get the public folder items.
-----

I already have code that works for the default calendar which is what you gave me.  If you know of any way of getting public folders (not objSession.GetDefaultFolder(0)), please let me know.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
SChertkov earned 300 total points
ID: 6320871
Any folder can be open by Session.GetFolder(folderID)
folderID is unique key generated on folder creation.
Following code dump all folders (include public)
and show it FolderID.

var
  objSession: OleVariant;
  Index: Integer;

procedure ShowFolder(Folder: OleVariant; const Pad: String);
var
  Folders: OleVariant;
begin
  ListBox1.Items.Add(Pad + Folder.Name + ' ['+ Folder.ID + ']');
  Folders := Folder.Folders;
  Folder := Folders.GetFirst;
  while not VarIsEmpty(Folder) do
    begin
      ShowFolder(Folder, Pad + ' ');
      Folder := Folders.GetNext;
    end;
end;

begin
  objSession := CreateOleObject('MAPI.Session');
  objSession.Logon;
  // List calendar folder
  for Index := 1 to objSession.InfoStores.Count do
    begin
      ListBox1.Items.Add(objSession.InfoStores[Index].Name);
      ShowFolder(objSession.InfoStores[Index].RootFolder, ' ');
    end;
  objSession.LogOff;
end;
0
 

Author Comment

by:NelsonR
ID: 6340278
Sorry for the delay... I've been pretty busy lately and haven't had a chance to try it out.  I should be able to do it sometime this week.  I think you've got the right answer.  If it works I'll give you the points.
0
 

Author Comment

by:NelsonR
ID: 6935462
Been a while.. :)  I had forgotten about this question.  I got it working with

var
 olOutlook, olNameSpace, olFolder, olItems, olRestrict, olItem: OleVariant;
begin
 olOutlook := CreateOleObject('Outlook.Application');
 olNameSpace := olOutlook.GetNameSpace('MAPI');
 olFolder := olNameSpace.Folders('Public Folders').Folders('All Public Folders').Folders('Whatever');
end;

It also works the way you mentioned it (with the ID), but it's easier to read 'Public Folders' than '3209823409823' or something :)

Anyway, I'll give it to you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
oracle global variables 4 80
Delphi...Split view - idea? 1 146
I want to use librsync in my Delphi backup application. 3 84
migrate this code to work on android 1 45
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question