none
Web config details in xaml file

    Question

  • Hi, i am working on silverlight project, i need to have all the node info on my xaml page in its code behind. How to call this web config file from my silverlight code behind. Please suggest a nice description or any related thread

    Regards

    SKM

    Monday, March 26, 2012 2:07 PM

Answers

  • Hi,

    A web.config is not supported in Silverlight. The System.Configuration namespace is doesn't exist in Silverlight.

    But you can write your own code for reading out the app settings of your config file by using the xml reader classes:

    public static string GetSomeSetting(string settingName)
            {
                var valueToGet = string.Empty;
                var reader = XmlReader.Create("XMLFileInYourRoot.Config");
                reader.MoveToContent();
    
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == "add")
                    {
                        if (reader.HasAttributes)
                        {
                            valueToGet = reader.GetAttribute("key");
                            if (!string.IsNullOrEmpty(valueToGet) && valueToGet == setting)
                            {
                                valueToGet = reader.GetAttribute("value");
                                return valueToGet;
                            }
                        }
                    }
                }
    
                return valueToGet;
            }
    Tuesday, March 27, 2012 2:13 AM