Home » Posts tagged 'Foundation'

Tag Archives: Foundation

SharePoint 2010: Setting Value for Web Part’s Custom Properties while Adding Web Part to Page Programmatically


To set the Custom Properties of web part through code while adding Web Part to Page programmatically, we can use Reflection to do this, Below is code on how to achieve this.

if (string.Equals(webPart.GetType().ToString(), “MyCustomWebpart”))
{
PropertyInfo[] pinProperties = webPart.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

foreach (PropertyInfo pinProperty in pinProperties)
{
if (pinProperty.Name == “Some Property”)
{
pinProperty.SetValue(webPart, “/Some Value”, null);
break;
}
}
}

Follow

Get every new post delivered to your Inbox.

Join 81 other followers