Monday 9 January 2012

Passing the value through Unsecure config to plugin CRM 2011


This is XML syntax code used in Unsecureconfig to pass the value to plugin.
<Settings>
        <setting name="adusername">
            <value>administrator</value>
        </setting>
       
<setting name="adpassword">
            <value>gangadhar_123</value>
        </setting>

<setting name="addomain">
            <value>locusit</value>
        </setting>
 
  </Settings>
 Below code is used to fetch the value from XML . paste this code in plugin(C#).

 private static string adusername = null;
       private static string adpassword  = null;
       private static string addomain = null;
   
public Class1(string unsecureConfig, string secureConfig)
       {
           XmlDocument doc = new XmlDocument();
           doc.LoadXml(unsecureConfig);

           adusername = GetValueNode(doc, "adusername");
           adpassword = GetValueNode(doc, "adpassword");
           addomain = GetValueNode(doc, "addomain");
 // adusername, password and addomain can make use of it anywhere in the solution or plugin .         
        }

        private static string GetValueNode(XmlDocument doc, string key)
        {
            XmlNode node = doc.SelectSingleNode(String.Format("Settings/setting[@name='{0}']", key));

            if (node != null)
            {
                return node.SelectSingleNode("value").InnerText;
            }
            return string.Empty;
        }

This is code done by our senior Technical Consultant Palani

No comments:

Post a Comment