我需要你的帮助。我是新创建的VSTO。此代码有效,并且创建了我想要的XML。但是,功能区和按钮不会显示在我的外观中。我正在使用OUTLOOK 365 ProPlus
我的想法是,当用户单击位于自定义功能区上的自定义按钮时;选定的电子邮件已保存到XML文件中。 “这是我的目标”
这是代码
这是我的类,称为Outlook
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Diagnostics;
using System.ComponentModel;
using System.Windows.Forms;
namespace OutlookAddIn1
{
public partial class ThisAddIn
{
XMLFileCreation xmlfile = new XMLFileCreation();
Outlook.Explorer currentExplorer = null;
// public ThisAddIn()
//{
//}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
//Globals.Ribbons.Ribbon1.button1.Checked = true;
currentExplorer = this.Application.ActiveExplorer();
currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
private void CurrentExplorer_Event()
{
Outlook.MAPIFolder selectedFolder =
this.Application.ActiveExplorer().CurrentFolder;
try
{
if (this.Application.ActiveExplorer().Selection.Count > 0)
{
Object seleObject = this.Application.ActiveExplorer().Selection[1];
Outlook.MailItem mailItem = (seleObject as Outlook.MailItem);
string Subject= mailItem.Subject.ToString();
string TO= mailItem.To.ToString();
string Body=mailItem.Body.ToString();
string SenderEmail=mailItem.SenderEmailAddress.ToString();
string SenderName=mailItem.SenderName .ToString();
xmlfile.CreateXMLFile(Subject, TO, SenderName, SenderEmail, Body);
}
}
catch
{
}
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
在这个类中,我打电话来创建一个XML文件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
namespace OutlookAddIn1
{
class XMLFileCreation
{
public void CreateXMLFile(string Subject, string TO, string SenderName,string SenderEmail,string Body)
{
XmlTextWriter xWrite = new XmlTextWriter("C:\\Users\\xxxxxxxx\\Desktop\\Outloot-Marketing\\Marketing.xml", Encoding.UTF8);
xWrite.Formatting = Formatting.Indented;
xWrite.WriteStartElement("Email");
xWrite.WriteStartElement("TO");
xWrite.WriteString(TO);
xWrite.WriteEndElement();
xWrite.WriteStartElement("FROM");
xWrite.WriteString(SenderName);
xWrite.WriteEndElement();
xWrite.WriteStartElement("SENDER_EMAIL");
xWrite.WriteString(SenderEmail);
xWrite.WriteEndElement();
xWrite.WriteStartElement("SUBJECT");
xWrite.WriteString(Subject);
xWrite.WriteEndElement();
xWrite.WriteStartElement("EMAIL_BODY");
xWrite.WriteString(Body);
xWrite.WriteEndElement();
xWrite.WriteEndElement();
xWrite.Close();
}
}
}
在这个课程中,我试图创建功能区和botton 我的想法是,当用户单击该botton时,所选电子邮件将另存为XML文件。但是,我在外观上没有成功显示功能区。我也需要显示丝带和波顿的帮助。感谢您的帮助。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Tools.Ribbon;
namespace OutlookAddIn1
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
// ThisAddIn mainapp = new ThisAddIn();
if (((RibbonToggleButton)sender).Checked)
{
MessageBox.Show("Hello");
}
else
{
MessageBox.Show("Hello from the else");
}
}
}
}