本文顺便记录下,如何读取sharepoint的15目录下,webconfig配置文件属性值的方法。
// <summary>
///读取/_layouts/15/目录下,webconfig配置方法
///</summary>
public static stringGetConnectionString(stringConnectionName)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
string CurrentPath = path + @"\CommonFiles\Microsoft Shared\web serverextensions\15\TEMPLATE\LAYOUTS\web.config";
XmlDocument doc = new XmlDocument();
doc.Load(CurrentPath);
XmlNode node = doc.SelectSingleNode("/configuration/connectionStrings/add[@name=\"" + ConnectionName + "\"]");
XmlElement element = (XmlElement)node;
string _connectionString = element.GetAttribute("connectionString");
return _connectionString;
}
// <summary>
///读取/_layouts/15/目录下,webconfig配置方法
///</summary>
public static string GetAppSettings(string AppSettingsKey)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
string CurrentPath = path + @"\CommonFiles\Microsoft Shared\web serverextensions\15\TEMPLATE\LAYOUTS\web.config";
XmlDocument doc = new XmlDocument();
doc.Load(CurrentPath);
XmlNode node = doc.SelectSingleNode("/configuration/appSettings/add[@key=\"" + AppSettingsKey + "\"]");
XmlElement element = (XmlElement)node;
string _connectionString = element.GetAttribute("value");
return _connectionString;
}