Get All Tasks In Outlook WinForms - vb.net

I will accept C# code as well. Will just convert it to VB.NET.
I'm having trouble retrieving tasks from outlook.
I have an application that writes a task to outlook.
The application can also mark a task as completed... but this is where my problem comes in.
What I want to achieve at the end is to mark a task as completed in my application and then it should also be marked as completed in outlook.
This is the code I have tried so far to retrieve the tasks, but now I dont know how to iterate through them to be able to mark a specific task as completed:
Dim namespce As Outlook.NameSpace
Dim tasks As Outlook.Items
Dim oApp = New Outlook.Application
namespce = oApp.GetNamespace("MAPI")
tasks = namespce.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).Items
For Each task As Object In tasks
'From here on I dont know any more
Next

C# code:
foreach(Outlook.TaskItem task in tasks)
{
bool isCompleeted = //Check if your task is compleeted in your application you could use EntryID property to identify a task
if(isCompleeted == true && task.Status != OlTaskStatus.olTaskComplete)
{
task.MarkComplete();
task.Save();
}
}

Related

Create new appointment on specific outlook calendar

I'm looking for Outlook VBA code that will create a new task on a specific outlook calendar??? For example, when I run the macro a new task opens. When I click "save", it will add the task to my non-default calendar "Notes/Tasks/Reminders".
You need to get the target calendar folder and then use the Items.Add method to create a new appointment there. Read more about all possible ways in the
How To: Create a new Outlook Appointment item article.
Dim appItem as Outlook.AppointmentItem
Dim items as Outlook.Items
Set items = yourCalendarFolder.Items
Set appItem = items.Add(olAppointmentItem)

How can I program Outlook to send an email in advance and send another if a reply isn't sent?

I'd like to program Outlook to send an email in advance, and, if no reply is sent to the target email by x date, send another email.
I've attempted experimentation, dabbling into Excel VBAs, but haven't found a solution.
I'm really quite unsure of how to do this, though I do have programming experience.
I'd like to program Outlook to send an email in advance
That is a very straightforward task. A lot of samples are available over the internet, for example, sample code in VB.NET:
Private Sub CreateSendItem(OutlookApp As Outlook._Application)
Dim mail As Outlook.MailItem = Nothing
Dim mailRecipients As Outlook.Recipients = Nothing
Dim mailRecipient As Outlook.Recipient = Nothing
Try
mail = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem)
mail.Subject = "A programatically generated e-mail"
mailRecipients = mail.Recipients
mailRecipient = mailRecipients.Add("Eugene Astafiev")
mailRecipient.Resolve()
If (mailRecipient.Resolved) Then
mail.Send()
Else
System.Windows.Forms.MessageBox.Show(
"There is no such record in your address book.")
End If
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message,
"An exception is occured in the code of add-in.")
Finally
If Not IsNothing(mailRecipient) Then Marshal.ReleaseComObject(mailRecipient)
If Not IsNothing(mailRecipients) Then Marshal.ReleaseComObject(mailRecipients)
If Not IsNothing(mail) Then Marshal.ReleaseComObject(mail)
End Try
End Sub
Read more about that in the following articles:
How To: Create and send an Outlook message programmatically
How To: Fill TO,CC and BCC fields in Outlook programmatically
How to create and show a new Outlook mail item programmatically: C#, VB.NET
if no reply is sent to the target email by x date, send another email.
You can set the following properties on the email:
MailItem.TaskDueDate which sets a Date value that represents the due date of the task for this MailItem.
MailItem.ReminderSet which sets a Boolean value that is True if a reminder has been set for this item.
MailItem.ReminderTime which sets a Date indicating the date and time at which the reminder should occur for the specified item.
In the Application.Reminder event handler you may check whether the mail item was replied or forwarded by reading a low-level property value. The property you would read would be PR_LAST_VERB_EXECUTED (0x10810003). Values are listed below:
EXCHIVERB_REPLYTOSENDER = 102
EXCHIVERB_REPLYTOALL = 103
EXCHIVERB_FORWARD = 104
Please remember that you can use the PropertyAccessor for that:
lastVerbExecuted = mailItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10810003")

Adding attendees to Outlook AppointmentItem (VB.NET)

I am trying to make an application in which i can send appointments to co-workers.
My code is as follows:
Public Sub SendAppointment()
Dim TempApp As Outlook.Application = New Outlook.Application()
'An AppointmentItem 'TempAppItem' object represent one appointment
Dim TempAppItem As Outlook.AppointmentItem = TempApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
TempAppItem.Subject = Onderwerp.SelectedItem
TempAppItem.Body = Opmerking.Text
'Set Location
'TempAppItem.Location = "No Location"
'Set start and end date and times
TempAppItem.Start = Convert.ToDateTime(Btijd.SelectedItem)
TempAppItem.End = Convert.ToDateTime(Etijd.SelectedItem)
'Save to Calendar.
TempAppItem.RequiredAttendees("some#emailaddress.com")
TempAppItem.Send()
TempAppItem.Save()
TempApp = Nothing
TempAppItem = Nothing
End Sub
If I leave out:
TempAppItem.RequiredAttendees("some#emailaddress.com")
It creates the appointment in my own calendar. This proves the rest of the code works. But somehow no matter which argument i add to RequiredAttendees, I keep getting errors. Mostly saying "Too many arguments to 'Property RequiredAttendees As String'.
In my eyes the easiest would be if I can just use the users e-mailaddress as a value to a variable, but somehow it seems vb.net only uses the stored name of said contact, which doesn't seem to work :\
I can't find any explanation of how to properly set the RequiredAttendees property and I am starting to break my head over this. Can anyone help me out or at least push me in the right direction?

Silverlight application using vb.net. Issue creating new email in lotus notes

Im writing a silverlight application in vb.net and need to send an email via lotus notes. I wish to do this by opening the lotus notes client app, open a new email window and substitute all the necessary details (to, subject etc.) in the new email window. I am using the below code but it only OPENS the lotus notes application on the machine, it does not do anything past this. Its seems that everything after the initial CreateObject call is simply ignored, although it doesnt throw any errors. I have attempt to reference interops.domino.dll but being silverlight project visual studio states the dll is not compiled for the silverlight runtime. Any assistance with this would be greatly appreciated.
Dim outlook = AutomationFactory.CreateObject("Notes.NotesSession")
Dim notesdb = outlook.GetDatabase("", "")
notesdb.OpenMail()
Dim doc = notesdb.CreateDocument()
Dim msg = "Hey whats up"
doc.ReplaceItemValue("SendTo", "person#temp.com")
doc.ReplaceItemValue("Subject", "Hello")
Dim rtitem = doc.CreateRichTextItem("Body")
rtitem.AppendText(msg)
All you do in the moment is to create a new document in the backend and fill it with values.
It is like creating a word document without opening it...
You need some more code to actually SHOW the document you created.
In addition you need to assign a Form, otherwise Notes will not know, how to display this document:
Dim session = AutomationFactory.CreateObject("Notes.NotesSession")
Dim notesdb = outlook.GetDatabase("", "")
Dim ws = AutomationFactory.CreateObject("Notes.NotesUIWorkspace")
notesdb.OpenMail()
Dim doc = notesdb.CreateDocument()
Dim msg = "Hey whats up"
doc.ReplaceItemValue("Form", "Memo")
doc.ReplaceItemValue("SendTo", "person#temp.com")
doc.ReplaceItemValue("Subject", "Hello")
Dim rtitem = doc.CreateRichTextItem("Body")
rtitem.AppendText(msg)
ws.EditDocument( True, doc )
As I do not use silverlight I unfortunately could not test the code, but It should point into the right direction.
You can not do UI manipulations via COM in Notes, as the UI-Classes (NotesUIDocument, NotesUIWorkspace, ...) are not supported via COM.
You can only use the backend-classes likes NotesDocument, ...
This still leaves you a lot of possibilites, as you can eiter use NotesRichTextItem or MIMEEntity classes to compose e-mails.

How to do Mailmerge in Openoffice using Vb.net

Its 5th Question and apart of one I didn't get response from the experts....
Hope this time I will get the helping hand.
I want to do mailmerge in openoffice using Vb.net and I am totally new with openoffice.
I searched on net for some help to understand how to use openoffice with vb.net but all I get is half info.....So can you please help me and give me code for mailmerge in vb.net for openoffice.
Well i have list of workers in DB and there is this facility that if they want to mail to all or some of the workers then they can do it.I have completed this task using Microsoft Office now as a Add in we are providing the facility to perform the same task using Open Office.
What they have to do is just select the List of workers and click on a button and it will automate the mailmerge using the field of those workers data from DB. The Code of mine is as shown below
Public Sub OpenOfficeMail(ByVal StrFilter As String)
Dim oSM ''Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object ''First objects from the API
Dim arg(-1) ''Ignore it for the moment !
''Instanciate OOo : this line is mandatory with VB for OOo API
oSM = CreateObject("com.sun.star.ServiceManager")
''Create the first and most important service
oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
''Create a new doc
oDoc = oDesk.loadComponentFromURL("private:factory/swriter", "_blank", 0, arg)
''Close the doc
oDoc.Close(True)
oDoc = Nothing
''Open an existing doc (pay attention to the syntax for first argument)
oDoc = oDesk.loadComponentFromURL("file:///C:\Users\Savan\Documents\1.odt", "_blank", 0, arg)
Dim t_OOo As Type
t_OOo = Type.GetTypeFromProgID("com.sun.star.ServiceManager")
Dim objServiceManager As New Object
objServiceManager = System.Activator.CreateInstance(t_OOo)
Dim oMailMerge As New Object
oMailMerge = t_OOo.InvokeMember("createInstance", Reflection.BindingFlags.InvokeMethod, Nothing, _
objServiceManager, New [Object]() {"com.sun.star.text.MailMerge"}) 'com.sun.star.text.MailMerge"})
oMailMerge.DocumentURL = "file:///C:\Users\Savan\Documents\1.odt"
oMailMerge.DataSourceName = CreateSource(StrFilter)''Function that will return the datasource name which will be a text file's path
oMailMerge.CommandType = 0
oMailMerge.Command = "file:///C:\Mail.txt"
oMailMerge.OutputType = 2
oMailMerge.execute(New [Object]() {})**---->I am getting Error here**
End Sub