c#自定义库

时间:2015-08-13 07:54:18

标签: c# sharepoint libraries

我正在创建一个用于发送电子邮件的自定义库。 想法是使用System.Net.MailMicrosoft.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存在,但该代码看不到它:(

0 个答案:

没有答案