我正在创建一个用于发送电子邮件的自定义库。
想法是使用System.Net.Mail
或Microsoft.SharePoint
。
代码将在具有System.Net.Mail
但不一定是Microsoft.SharePoint
的环境中执行。
只有在配置文件中设置了Sharepoint地址时才会使用Sharepoint库。
问题是如果整个库不存在于已执行的环境中,如何使用Microsoft.SharePoint
库而不会崩溃程序?
我不想添加Microsoft.SharePoint
库,因为它违反了Microsoft规则。
If(Enviroment.Libraries.Contains(Microsoft.Sharepoint)
Use Microsoft.Sharepoint
Else
Use System.Net.Mail
:)
这是问题所在:
Could not load file or assembly 'Microsoft.SharePoint, Version=14.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies.
The system cannot find the file specified.
我试过了
using (Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Shared Tools\\Web Server Extensions\\14.0", false))
{
if (regKey != null)
{
string installStatus = System.Convert.ToString(regKey.GetValue("SharePoint"), System.Globalization.CultureInfo.InvariantCulture);
if (!string.IsNullOrEmpty(installStatus) && installStatus.Equals("Installed", System.StringComparison.OrdinalIgnoreCase))
{
System.Console.WriteLine("Installed");
}
}
System.Console.WriteLine("NOT Installed");
}
我可以看到(使用regedit)SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\SharePoint
存在,但该代码看不到它:(