本文顺便记录下,如何读取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;
}
本文提供了一种方法,用于从SharePoint的15目录下的web.config文件中读取连接字符串和应用程序设置。通过使用XMLDocument类加载配置文件并选取特定节点来获取所需的配置值。
3196

被折叠的 条评论
为什么被折叠?



