sharepoint 读取/_layouts/15/目录webconfig配置方法

来源:互联网 发布:江苏省困难职工数据库 编辑:程序博客网 时间:2024/06/05 09:42

本文顺便记录下,如何读取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;

       }


原创粉丝点击