Мне нужна твоя помощь. Я новичок в создании ВСТО. Этот код работает, и он создает мой 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 file
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();
}
}
}
В этом классе я пытаюсь создать ленту и кнопку. Моя идея состоит в том, что когда пользователь нажимает на кнопку, выбранная электронная почта будет сохранена как файл 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");
}
}
}
}