Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access Outlook Public Calendar Folders

Posted on 2001-07-24
6
Medium Priority
?
786 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Accepted Solution

by:
SChertkov earned 900 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

Technology Partners: 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

704 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