【发布时间】:2022-08-04 21:23:47
【问题描述】:
我正在使用语言 c#。我让 Outlook 通过 VSTO 运行,但似乎无法让我希望 Outlook 正确读取的文本文件运行。文本文件包含一个名称列表,如果 Outlook 中的名称与文本文件中的名称匹配,我想让它通过 Outlook 自动查找它,以便给我一个真或假的陈述。我希望它逐行读取文本文件。到目前为止,这是我的代码:
namespace OutlookAddIn1
{
public partial class ThisAddIn
{
private static int Main(string[] args)
{
System.Diagnostics.Debug.WriteLine(\"hello\");
Console.WriteLine(\"test\");
string filePath = @\"C:\\Users\\Desktop\\QC\\User_.txt\";
string filePath2 = @\"C:\\Users\\Documents\\QC\\userlist.txt\";
List<string> lines = File.ReadAllLines(filePath).ToList();
Console.WriteLine(lines);
foreach (string line in lines)
{
Console.WriteLine(line);
}
lines.Add(\"True\");
List<string> list = new List<string>();
string inSystem = \"\";
lines = File.ReadAllLines(filePath).ToList();
using (StreamWriter sw = new StreamWriter(filePath)) ;
string OutLook_Username_Output = \"\";
foreach (string line in lines)
{
if (line.Equals(OutLook_Username_Output))
{
inSystem += \"true\" + Environment.NewLine;
}
else
{
inSystem += \"false\" + Environment.NewLine;
}
System.Diagnostics.Debug.WriteLine(\"true\");
Console.WriteLine(line);
for (int i = 0; i < lines.Count; i++)
{
Console.WriteLine(lines[i] + \":\" + inSystem[i]);
}
File.WriteAllText(@\"C:\\Users\\059974\\Documents\\QC\\userlist.txt\",inSystem );
return 0;
}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// Note: Outlook no longer raises this event. If you have code that
// must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785
}
#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);
}
return 0;
#endregion
}
}
-
为什么需要在 VSTO 加载项中使用
Main方法? -
我不确定,我用什么来代替它?
-
通常,当加载项启动时会调用
ThisAddin类的Startup方法(请参阅代码中的ThisAddIn_Startup)。 -
那么我是否应该将我拥有的所有代码放在 Main 下并将其放在 ThisAddIn_Startup 下,然后删除 Main ?
-
如果您不使用加载项的事件处理程序,您的代码将不会运行。
标签: c# outlook vsto outlook-addin office-addins