I want to set a custom property value when add web part programmatically.
This is my code for add web part in page:
using (SPLimitedWebPartManager manager = oWeb.GetLimitedWebPartManager(newPage.Url, PersonalizationScope.Shared))
{
try
{
string wPartURL = oWeb.Site.Url + "/_catalogs/wp/ClientViewProjects.webpart";
XmlTextReader reader = new XmlTextReader(new StringReader(oWeb.GetFileAsString(wPartURL)));
string err = null;
System.Web.UI.WebControls.WebParts.WebPart wp = (System.Web.UI.WebControls.WebParts.WebPart)manager.ImportWebPart(reader, out err);
wp.ChromeType = PartChromeType.None;
manager.AddWebPart(wp, "Header", 0); //See the description below for how to determine Zone
manager.SaveChanges(wp);
}
catch (Exception ex)
{
LOG_STRING += string.Format("В сайт с URL:{0}{1} {2}", oWeb.ServerRelativeUrl, ex.ToString(), Environment.NewLine);
}
finally
{
manager.Web.Dispose();
}
newPage.CheckIn("Checked in by Code");
newPage.ListItem.File.Publish("Publishing major version");
}