I am creating a custom library for sending emails.
Idea is to use System.Net.Mail
or Microsoft.SharePoint
.
Code will be executed in enviroment that has System.Net.Mail
but not necessarily Microsoft.SharePoint
.
Sharepoint library will be used only if Sharepoint address is set in configuration file.
The question is how to use Microsoft.SharePoint
library without crashing program if whole library doesnt exist in a executed enviroment?
I do not want to add Microsoft.SharePoint
library because it is against Microsoft rules.
If(Enviroment.Libraries.Contains(Microsoft.Sharepoint)
Use Microsoft.Sharepoint
Else
Use System.Net.Mail
:)
This is the problem:
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.
I have tried
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");
}
I can see (using regedit) that SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\SharePoint
is there but that code just does not see it :(