SharePoint Property Bag

Don’t muck with the web.config in SharePoint 2010. Store and access connection strings and other key-value pairs in the SharePoint Property Bag.

Here’s code for retrieving the connection string:

</pre><p>            SqlCommand mySqlCmd= new SqlCommand();<br />            using (SPSite site = SPContext.Current.Site)<br />            {<br />                using (SPWeb web = site.OpenWeb())<br />                {<br />            try<br />            {<br />                mySqlCmd.Connection = new SqlConnection(web.AllProperties["myConnectionString"].ToString());</p><pre>

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s