Get Tasks in Outlook 2007 with VB.NET

You can retrieve the list of tasks in your Outlook 2007 using the following code

Dim ns As Outlook.NameSpace
Dim tasks As Outlook.Items
ns = Application.GetNamespace(“MAPI”)
tasks = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).Items

Dim task As Object
For Each task In tasks
    ‘ iterate through the tasks here
Next

Advertisements

0 thoughts on “Get Tasks in Outlook 2007 with VB.NET

  1. For Each task In tasks ‘ iterate through the tasks hereNext…ARGH!How do I actually get to the tasks then?how do I acess the subject, for example?Anytime I try using an object like dim task as outlook.taskitem I get a NULL reference exception.If I usedim task as new outlook.taskitem() I get a “can not be used in this context, as outlook.classitem is FRIEND”help, please?

    Like

  2. For Each task In tasks
    ‘ iterate through the tasks here
    Next


    ARGH!

    How do I actually get to the tasks then?
    how do I acess the subject, for example?

    Anytime I try using an object like
    dim task as outlook.taskitem I get a NULL reference exception.
    If I use
    dim task as new outlook.taskitem() I get a “can not be used in this context, as outlook.classitem is FRIEND”

    help, please?

    Like

  3. One more thing… if you want to create a new task, you do it like this:Dim MyApp As Outlook.Application = New Outlook.Application()Dim outlookTask As Outlook.TaskItem = MyApp.Application.CreateItem(Outlook.OlItemType.olTaskItem)

    Like

  4. The way I get the outlook tasks is like this:

    ‘get outlook tasks
    Dim ns As Outlook.NameSpace

    ns = MyApp.Application.GetNamespace(“MAPI”)

    outlookTasksAll = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).Items

    outlookTasks = (From outlookTask As Outlook.TaskItem In outlookTasksAll _
    Where outlookTask.Status Outlook.OlTaskStatus.olTaskComplete _
    ).ToList

    You can take a look at my open source project that syncs RTM with Outlook you might find what you are looking for in the source code. There is more info at http://www.emadibrahim.com/2008/04/14/synchronize-outlook-tasks-with-remember-the-milk/

    Like

  5. One more thing… if you want to create a new task, you do it like this:

    Dim MyApp As Outlook.Application = New Outlook.Application()

    Dim outlookTask As Outlook.TaskItem = MyApp.Application.CreateItem(Outlook.OlItemType.olTaskItem)

    Like

  6. @captain: The code in my first comment doesn't create a task it retrieves all the tasks… Here it is again:Dim ns As Outlook.NameSpacens = MyApp.Application.GetNamespace(”MAPI”)outlookTasksAll = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).ItemsAgain, you can download the source code from the link in my first comment and take a look at it.

    Like

  7. @captain: The code in my first comment doesn’t create a task it retrieves all the tasks… Here it is again:

    Dim ns As Outlook.NameSpace
    ns = MyApp.Application.GetNamespace(”MAPI”)
    outlookTasksAll = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).Items

    Again, you can download the source code from the link in my first comment and take a look at it.

    Like

  8. Thanks a bunch.Yes, I have seen that your code did not create a task, I was commenting on your comment:”One more thing… if you want to create a new task, you do it like this:Dim MyApp As Outlook.Application = New Outlook.Application()Dim outlookTask As Outlook.TaskItem = MyApp.Application.CreateItem(Outlook.OlItemType.olTaskItem)”You have helped me a lot, thank you again!

    Like

  9. Thanks a bunch.

    Yes, I have seen that your code did not create a task, I was commenting on your comment:

    “One more thing… if you want to create a new task, you do it like this:

    Dim MyApp As Outlook.Application = New Outlook.Application()

    Dim outlookTask As Outlook.TaskItem = MyApp.Application.CreateItem(Outlook.OlItemType.olTaskItem)”

    You have helped me a lot, thank you again!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s