Solved

Access Outlook Public Calendar Folders

Posted on 2001-07-24
6
767 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
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!

 
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connection between libmysql.dll and MySQL Versions 7 119
Create a path if not exists 7 108
Graphics32 under Delphi 10.1 Berlin 2 125
Twebbrowser add css to the header 3 38
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

763 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