using (SPSite oSPsite = new SPSite("url"))
{
oSPsite.AllowUnsafeUpdates = true;
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{ oSPWeb.AllowUnsafeUpdates = true;
SPWebPartCollection colWebParts = oSPWeb.GetWebPartCollection(
Storage.Shared);
"absolute url of the webpart page",
foreach (WebPart webPart in colWebParts)
{
if (webPart.GetType().ToString() ==
"Microsoft.Sharepoint.WebPartPages.PageViewerWebPart")
{
PropertyInfo[] wptProperties = webPart.GetType().GetProperties(
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo property in wptProperties)
{
if (property.Name == "ContentLink")
{
//set new content link property and save changes
property.SetValue(webPart, "new content link url", null);
colWebParts.SaveChanges(webPart.StorageKey);
break;
}
}
break;
}
}
oSPWeb.AllowUnsafeUpdates = false;
}
oSPsite.AllowUnsafeUpdates = false;
}