Calender folder returns no appointments

Discussion in 'Microsoft Outlook Interoperability' started by Mk23, Mar 17, 2009.

  1. Mk23

    Mk23 Guest

    Hi

    I have a problem by getting the appointment from an calendar folder. I use
    the PIA from Office XP and have a Outlook 2007. At the most customer it works
    fine, but at a few PC's it doesn't work. That mean, i get no appointment
    items, althought the user has a lot of them in his calendar.

    I get the items by the following sample code:

    //Select folder
    Microsoft.Office.Interop.Outlook.Application app = new
    Microsoft.Office.Interop.Outlook.Application();
    NameSpace olNameSpace = app.Session;
    olFolder = olNameSpace.PickFolder();

    //Create filter string
    CultureInfo userCulture = new CultureInfo(GetUserDefaultLCID());
    string restrictExpression = string.Format("[Start]>='{0}' AND
    [Start]<'{1}'",
    _dateFrom.Value.ToString("g", userCulture.DateTimeFormat),
    _dateTill.Value.ToString("g", userCulture.DateTimeFormat));

    //Get filtered items and sort them
    Items folderItems = olFolder.Items;
    Items restrictedItems = folderItems.Restrict(restrictExpression);
    restrictedItems.Sort("[Start]", Missing.Value);

    //Loop all appointment elements
    object itemObject = restrictedItems.GetFirst();
    while (itemObject != null)
    {
    ...
    }

    Does anyone have an hint for me

    Regards
    Thomas
     
    Mk23, Mar 17, 2009
    #1
    1. Advertisements

  2. Is this an outside program or a COM addin?

    In either case I'd recommend setting NameSpace by using GetNameSpace("MAPI")
    and not just by referencing Session. Although I don't think that has
    anything to do with your problem.

    Does the code run all the way through with no exceptions? Have you been able
    to step the code in debug mode and see what's happening? What about
    diagnostic logging, are you doing any so you can check at various
    checkpoints to see what values are there for key objects such as your filter
    string, the default item type for the folder selected from PickFolder(), the
    raw count of both the filtered and unfiltered Items collections, etc?

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007.
    Reminder Manager, Extended Reminders, Attachment Options.
    http://www.slovaktech.com/products.htm


    "Mk23" <> wrote in message
    news:...
    > Hi
    >
    > I have a problem by getting the appointment from an calendar folder. I use
    > the PIA from Office XP and have a Outlook 2007. At the most customer it
    > works
    > fine, but at a few PC's it doesn't work. That mean, i get no appointment
    > items, althought the user has a lot of them in his calendar.
    >
    > I get the items by the following sample code:
    >
    > //Select folder
    > Microsoft.Office.Interop.Outlook.Application app = new
    > Microsoft.Office.Interop.Outlook.Application();
    > NameSpace olNameSpace = app.Session;
    > olFolder = olNameSpace.PickFolder();
    >
    > //Create filter string
    > CultureInfo userCulture = new
    > CultureInfo(GetUserDefaultLCID());
    > string restrictExpression = string.Format("[Start]>='{0}' AND
    > [Start]<'{1}'",
    > _dateFrom.Value.ToString("g", userCulture.DateTimeFormat),
    > _dateTill.Value.ToString("g", userCulture.DateTimeFormat));
    >
    > //Get filtered items and sort them
    > Items folderItems = olFolder.Items;
    > Items restrictedItems =
    > folderItems.Restrict(restrictExpression);
    > restrictedItems.Sort("[Start]", Missing.Value);
    >
    > //Loop all appointment elements
    > object itemObject = restrictedItems.GetFirst();
    > while (itemObject != null)
    > {
    > ...
    > }
    >
    > Does anyone have an hint for me
    >
    > Regards
    > Thomas
     
    Ken Slovak - [MVP - Outlook], Mar 17, 2009
    #2
    1. Advertisements

  3. Mk23

    Mk23 Guest

    Hi Ken

    - The main application is a COM addin. But i wrote a smal sample project
    with just the necessary code to get the calendar item. This sample is an
    outside program. I can reproduce the error with both.
    - The code run through with no exception.
    - I ckeck the item type for the folder, so that it has to be a calendar.
    - I can't reproduce the exception at an own system, only at the customer.
    There I'am not able to debug.
    - I have made a few logging to see the state of some object's.

    That for the moment. I will post a few more info's when i have all
    information you asked for.
     
    Mk23, Mar 17, 2009
    #3
  4. Mk23

    Mk23 Guest

    Hi Ken

    Here I have a few more Informations from the customer log:
    DefaultItemType: olAppointmentItem
    restriction expression: [Start]>='18.02.2009 00:00' AND
    [Start]<'18.05.2009 00:00'
    UnfilteredItems: 404
    FilteredItems: 0

    So it seems to be a problem with the restriction expression. How has this
    string to be formated, that it work?

    I checked this string at my own system, there I have the same string and it
    work's fine. My personal log:
    restriction expression: [Start]>='18.02.2009 00:00' AND [Start]<'18.05.2009
    00:00'
    UnfilteredItems: 405
    FilteredItems: 124

    Regards Thomas
     
    Mk23, Mar 18, 2009
    #4
  5. The VBA Object Browser Help on Restrict says you should format the date
    string so it's formatted as Outlook expects. The example there is this,
    using LastModificationTime as the field in the filter:

    sFilter = "[LastModificationTime] > '" & Format("1/15/99 3:30pm", "ddddd
    h:nn AMPM") & "'"

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007.
    Reminder Manager, Extended Reminders, Attachment Options.
    http://www.slovaktech.com/products.htm


    "Mk23" <> wrote in message
    news:...
    > Hi Ken
    >
    > Here I have a few more Informations from the customer log:
    > DefaultItemType: olAppointmentItem
    > restriction expression: [Start]>='18.02.2009 00:00' AND
    > [Start]<'18.05.2009 00:00'
    > UnfilteredItems: 404
    > FilteredItems: 0
    >
    > So it seems to be a problem with the restriction expression. How has this
    > string to be formated, that it work?
    >
    > I checked this string at my own system, there I have the same string and
    > it
    > work's fine. My personal log:
    > restriction expression: [Start]>='18.02.2009 00:00' AND
    > [Start]<'18.05.2009
    > 00:00'
    > UnfilteredItems: 405
    > FilteredItems: 124
    >
    > Regards Thomas
     
    Ken Slovak - [MVP - Outlook], Mar 18, 2009
    #5
  6. Mk23

    Mk23 Guest

    Yes this hint i have seen also.
    But this can't be true, because inside the 'AMPM' part of this format string
    the 'M' character will be replaced with the Minute part of the formated Date
    (tested in C#)!
     
    Mk23, Mar 18, 2009
    #6
  7. C# is not VBA. You must use the equivalent formatting that is appropriate
    for C#. Run the line used in the example in Outlook VBA code and see that it
    doesn't use the M of AMPM in the way you describe.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007.
    Reminder Manager, Extended Reminders, Attachment Options.
    http://www.slovaktech.com/products.htm


    "Mk23" <> wrote in message
    news:...
    > Yes this hint i have seen also.
    > But this can't be true, because inside the 'AMPM' part of this format
    > string
    > the 'M' character will be replaced with the Minute part of the formated
    > Date
    > (tested in C#)!
     
    Ken Slovak - [MVP - Outlook], Mar 18, 2009
    #7
  8. Mk23

    Mk23 Guest

    Hi Ken

    Naturally you have right with the replacement, sorry.

    But on the other side it doesn't help anything if I format the string the
    way you/the help discribe. It is still the same, it doesn't work.

    The formated string was:
    [Start]>='2/19/2009 12:00 AM' AND [Start]<'5/19/2009 12:00 AM'

    Regards Thomas

    "Ken Slovak - [MVP - Outlook]" wrote:

    > C# is not VBA. You must use the equivalent formatting that is appropriate
    > for C#. Run the line used in the example in Outlook VBA code and see that it
    > doesn't use the M of AMPM in the way you describe.
    >
    > --
    > Ken Slovak
    > [MVP - Outlook]
    > http://www.slovaktech.com
    > Author: Professional Programming Outlook 2007.
    > Reminder Manager, Extended Reminders, Attachment Options.
    > http://www.slovaktech.com/products.htm
    >
    >
    > "Mk23" <> wrote in message
    > news:...
    > > Yes this hint i have seen also.
    > > But this can't be true, because inside the 'AMPM' part of this format
    > > string
    > > the 'M' character will be replaced with the Minute part of the formated
    > > Date
    > > (tested in C#)!

    >
    >
     
    Mk23, Mar 23, 2009
    #8
  9. All I can suggest is to use Debug.WriteLine() to show the filter you end up
    with in C# and then use the original VBA code and see what that filter looks
    like. Make sure they look the same. Also make sure that the VBA code works
    as expected when you run it using that filter.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007.
    Reminder Manager, Extended Reminders, Attachment Options.
    http://www.slovaktech.com/products.htm


    "Mk23" <> wrote in message
    news:...
    > Hi Ken
    >
    > Naturally you have right with the replacement, sorry.
    >
    > But on the other side it doesn't help anything if I format the string the
    > way you/the help discribe. It is still the same, it doesn't work.
    >
    > The formated string was:
    > [Start]>='2/19/2009 12:00 AM' AND [Start]<'5/19/2009 12:00 AM'
    >
    > Regards Thomas
     
    Ken Slovak - [MVP - Outlook], Mar 23, 2009
    #9
  10. Mk23

    Mk23 Guest

    At the end we placed a call to microsoft.
    We tried a lot of things, but didn't find the reason, for this strange
    behaviour. In the end we deleted the profile of the user and it worked again.
     
    Mk23, May 25, 2009
    #10
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert

    Delegate getting error in Calender

    Robert, Dec 23, 2003, in forum: Microsoft Outlook Interoperability
    Replies:
    0
    Views:
    147
    Robert
    Dec 23, 2003
  2. bretski

    can only view 3 months of other users calender

    bretski, Jan 30, 2004, in forum: Microsoft Outlook Interoperability
    Replies:
    4
    Views:
    206
    bretski
    Feb 10, 2004
  3. Guest

    Outlook Hangs in Calender

    Guest, Jul 30, 2004, in forum: Microsoft Outlook Interoperability
    Replies:
    0
    Views:
    247
    Guest
    Jul 30, 2004
  4. Guest

    Calender ahs me scheduled busy

    Guest, Nov 10, 2004, in forum: Microsoft Outlook Interoperability
    Replies:
    1
    Views:
    200
    Guest
    Nov 10, 2004
  5. Manuel M.

    Outlook Object Model returns new id of public folder items

    Manuel M., Jan 14, 2010, in forum: Microsoft Outlook Interoperability
    Replies:
    8
    Views:
    1,219
    Brian Tillman [MVP-Outlook]
    Feb 12, 2010
Loading...

Share This Page