Fetching values from Web.config in SharePoint in webapplication level if scope is site it won't allow directly to web.config we can able to fetch the data using below method
public string GetConnectionstring(string Url, string Key)
{
try
{
using (SPSite site = new SPSite(Url))
{
Configuration config = WebConfigurationManager.OpenWebConfiguration("/", site.WebApplication.Name);
return config.AppSettings.Settings[Key].Value;
}
}
catch (Exception ex)
{
logToList(ex.Message);
return string.Empty;
}
}
public string GetConnectionstring(string Url, string Key)
{
try
{
using (SPSite site = new SPSite(Url))
{
Configuration config = WebConfigurationManager.OpenWebConfiguration("/", site.WebApplication.Name);
return config.AppSettings.Settings[Key].Value;
}
}
catch (Exception ex)
{
logToList(ex.Message);
return string.Empty;
}
}
No comments:
Post a Comment