Solved

Access Outlook Public Calendar Folders

Posted on 2001-07-24
6
742 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
  • 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now