Random Musings

June 12, 2009

Using App.Config in C# dll library

Filed under: Dynamics CRM — haditeo @ 5:03 pm
Tags: ,

Here are the steps to use App.Config in dll;
1) Make sure that the build action of the App.Config is ‘Content’ and Copy to Output Directory = ‘Copy always’
2) Make sure that the App.Config file is placed in the \bin\Debug folder
3) Read the App.Config by using XmlDocument.Load() method

            XmlDocument doc = new XmlDocument();
            doc.Load(AppDomain.CurrentDomain.BaseDirectory + "\\" + "App.Config");

            XmlNode appSettingsNode = doc.GetElementsByTagName("appSettings")[0];

            foreach(XmlNode node in appSettingsNode.ChildNodes)
                switch (node.Attributes["key"].Value)
                    case "Domain":
                        nc.Domain = node.Attributes["value"].Value;
                    case "UserName":
                        nc.UserName = node.Attributes["value"].Value;
                    case "Password":
                        nc.Password = node.Attributes["value"].Value;
                    case "AuthenticationType":
                        token.AuthenticationType = Convert.ToInt32(node.Attributes["value"].Value);
                    case "OrgName":
                        token.OrganizationName = node.Attributes["value"].Value;
                    case "CrmUrl":
                        crmService.Url = node.Attributes["value"].Value;

The purpose of the AppDomain.CurrentDomain.BaseDirectory property is to locate the actual path of the \bin\Debug folder


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: