DLLImportAttribute C# - Outlook

不羁岁月 提交于 2019-12-10 12:33:53

问题


I'm trying to develop a snippet in C # code that enables the "voting option" function of Outlook.

This code will be used by a platform called Blue Prism.

The "vote" function of Outlook is in the Microsoft.Office.Interop.Outlook namespace, so I need to import it using C#, but I dont have enough knowledge to develop this.

I tried to do something like this but it is giving an error. Here is the code:

public class program {

[DllImport(@"C:\Program Files\Blue Prism Limited\Blue Prism Automate\Microsoft.Office.Interop.Outlook.dll", EntryPoint = "VotingOptions")]
public static extern string Outlook(uint type);

static void Main()
{
    // Create the Outlook application.
    Outlook.Application  oApp = new Outlook.Application();
oApp.VotingOption = "Yes; No";
}

}

So, can someone help me?


回答1:


The VotingOptions property belongs to the MailItem class , not Outlook Application. Voting options on messages are used to give message recipients a list of choices and to track their responses. To create voting options programmatically, set a string that is a semicolon-delimited list of values for the VotingOptions property of a MailItem object. The values for the VotingOptions property will appear under the Vote command in the Respond group in the ribbon of the received message.

 private void OrderPizza()
 {
    Outlook.MailItem mail = (Outlook.MailItem)Application.CreateItem(
       Outlook.OlItemType.olMailItem);
    mail.VotingOptions = “Cheese; Mushroom; Sausage; Combo; Veg Combo;”
    mail.Subject = “Pizza Order”;
    mail.Display(false);
 }

Also you may find the C# app automates Outlook (CSAutomateOutlook) sample project helpful, it shows how to automate Outlook in C#.




回答2:


Com objects aren't accessed through DLLImport. They're accessed using references. From the sample Eugene linked:

Create a Console application and reference the Outlook Primary Interop Assembly (PIA). To reference the Outlook PIA, right-click the project file and click the "Add Reference..." button. In the Add Reference dialog, navigate to the .NET tab, find Microsoft.Office.Interop.Outlook 12.0.0.0 and click OK.

Now you'll have access to the Microsoft.Office.Interop.Outlook object.




回答3:


If you are using Blue Prism then rather than having to specify DLL references you may also chose to go the GetObject or CreateObject way, you will be able to interact with Outlook just like Blue Prism does with Excel. The drawback of this approach is that you have to use VB.NET (unless I am mistaken) and that you will not be able to use text representation of enum values (so for OlItemType you will not be able to use olMailItem but only its numeric value, which is 0).

Please note that Blue Prism has released a new version recently (6.3) and with it a new VBO for interaction with Outlook. It's nothing revolutionary, but it may provide some insight.



来源:https://stackoverflow.com/questions/51344804/dllimportattribute-c-sharp-outlook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!