Pathik's Blog

Home » Posts tagged 'SharePoint Object Model'

Tag Archives: SharePoint Object Model

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);


Get every new post delivered to your Inbox.

Join 135 other followers