Search code examples
c#asp.netconfigurationconfigwebconfigurationmanager

read custom config file in asp.net


How do I read connection strings from custom config file (say abc.config) using WebConfigurationManager from asp.net's C# code?

Configuration conf = WebConfigurationManager.OpenWebConfiguration("~/abc.config");

This doesn't seem to work.


Solution

  • I dont think you can read it with webconfigurationmanager. you will have read like any xml file as it is an xml file

    public static string GetSingleValue(string strXPathExpression, string strAttributeName)
            {
                XmlNode node = GetNode(strXPathExpression);
                if (node != null)
                {
                    XmlAttribute attribute = node.Attributes[strAttributeName];
                    if (attribute != null)
                        return attribute.Value;
                }
    
                return string.Empty;
    
    
            }