是否有可能在 WPF 中捕获 Pc Microsoft 帐户信息,例如 maild Id。 我遇到了 Microsoft.Office.Interop.Outlook,但在使用它时出现错误。以下是我正在尝试使用的代码
public void GetDetails()
{
try
{
// Create the Outlook application.
// in-line initialization
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
// Get the MAPI namespace.
Microsoft.Office.Interop.Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using the default profile or existing session (no dialog box).
oNS.Logon(Missing.Value, Missing.Value, false, true);
// Alternate logon method that uses a specific profile name.
// TODO: If you use this logon method, specify the correct profile name
// and comment the previous Logon line.
//oNS.Logon("profilename",Missing.Value,false,true);
//Get the Inbox folder.
Microsoft.Office.Interop.Outlook.MAPIFolder oInbox = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
//Get the Items collection in the Inbox folder.
Microsoft.Office.Interop.Outlook.Items oItems = oInbox.Items;
// Get the first message.
// Because the Items folder may contain different item types,
// use explicit typecasting with the assignment.
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oItems.GetFirst();
//Output some common properties.
Console.WriteLine(oMsg.Subject);
Console.WriteLine(oMsg.SenderName);
Console.WriteLine(oMsg.ReceivedTime);
Console.WriteLine(oMsg.Body);
//Check for attachments.
int AttachCnt = oMsg.Attachments.Count;
Console.WriteLine("Attachments: " + AttachCnt.ToString());
//TO DO: If you use the Microsoft Outlook 10.0 Object Library, uncomment the following lines.
/*if (AttachCnt > 0)
{
for (int i = 1; i <= AttachCnt; i++)
Console.WriteLine(i.ToString() + "-" + oMsg.Attachments.Item(i).DisplayName);
}*/
//TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following lines.
/*if (AttachCnt > 0)
{
for (int i = 1; i <= AttachCnt; i++)
Console.WriteLine(i.ToString() + "-" + oMsg.Attachments[i].DisplayName);
}*/
//Display the message.
oMsg.Display(true); //modal
//Log off.
oNS.Logoff();
//Explicitly release objects.
oMsg = null;
oItems = null;
oInbox = null;
oNS = null;
oApp = null;
}
//Error handler.
catch (Exception e)
{
Console.WriteLine("{0} Exception caught: ", e);
}
}
-> 我已经从 NuGet 安装了一个包。
-> 我得到的错误是:Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified
试图解决这个错误,但在实现这一点上没有任何改进。
是否有更好的方法来读取登录 PC 的 Microsoft 帐户详细信息。