I am creating a method that will iterate through all of the web parts on a page in my SharePoint site. What I need to do is update a custom web part's, created by another company, property. I have gone through all of the properties for the web part using C# and none of the values returned are what i am looking for.
Here is my C# code,
private void GetWebParts()
{
// What site you are using.
using (SPSite site = new SPSite("http://site..com/sites/dept/"))
{
// Returns the Web site that is located at the specified server-relative or site-relative URL.
using (SPWeb web = site.OpenWeb())
{
// Give the file name you are looking for.
SPFile file = web.GetFile("SitePages/FNDisposalRequestICV.aspx");
using (SPLimitedWebPartManager wpm = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
// Loop through all of the web parts on the page.
foreach (SysUI.WebPart wp in wpm.WebParts)
{
// Here is where I should be able to get and update all of the
// web part properties. For some reason I am unable to get all
// of the custom web part properties but am able to get the
// "standard" ones i.e. Title, TitleUrl...
wp.Title;
// Saves the changes of any updates you made to the web part.
//wpm.SaveChanges(wp);
}
}
}
}
}
Is there a certain class to use that is used for custom web parts? Or am i missing a step somewhere in my code?
EDIT
I have exported the custom web part where i need to get the data. The Property does exist and has a value. When I go to my C# code and try to access this property, I get an error saying it doesn't exist.