views:

24

answers:

0

I'm using outlook api for sending task in a web application application. I'm also trying to save task, for saving task it gives error - "Could not complete the operation. One or more parameter values are not valid."

 private static void CreateTaskO(Request instance, string email, string msgBody)
    {
        Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();
        Microsoft.Office.Interop.Outlook.TaskItem oTask = (Microsoft.Office.Interop.Outlook.TaskItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olTaskItem);

        oTask.Subject = "Project Status -" + instance.Project.Name + " - " + instance.Description;

        oTask.DueDate = instance.CompletionDate.Value;

        //oTask.StartDate = instance.st;

        oTask.ReminderSet = true;

        oTask.Body = msgBody;
        string filename = @"C:\temp\" + Guid.NewGuid().ToString() + ".ics";


        oTask.Status = Microsoft.Office.Interop.Outlook.OlTaskStatus.olTaskInProgress;

        //oTask.Recipients.Add("[email protected]");
        oTask.Recipients.Add(email);

        oTask = oTask.Assign();
        oTask.SaveAs(filename, Microsoft.Office.Interop.Outlook.OlSaveAsType.olICal);
        //oTask.Send();
    }

In SaveAs function if I give type (OlSaveAsType) as txt than it works, if I give type as ical or vcal it gives error.

MSDN documentation says "Saves the Microsoft Outlook item to the specified path and in the format of the specified file type. If the file type is not specified, the MSG format (.msg) is used." But if I did not specify type, it gives error that function need 2 arguments.