// get the site in this context
using (SPSite SiteCollection = new SPSite(mySiteGuid))
// get the web in this context
SPWeb myWeb = SiteCollection.OpenWeb(myWebGuid);
myWeb .AllowUnsafeUpdates = true;
// Hide/display another webpart.
Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null;
mgr = myWeb.GetLimitedWebPartManager("default.aspx",System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
foreach (System.Web.UI.WebControls.WebParts.WebPart myWebPart in mgr.WebParts)
// If this is the webpart we want to modify...
if(myWebPart.Title == "Other Webpart Name")
// Toggle the visibility state.
myWebPart.Visible = !myWebPart.Visible;
code above is just looping through the webparts within the webpart manager, as your using the foreach WebPart means the varible (object) myWebPart is a webpart, you then check to make sure its the webpart you want with an if statment, within the if you can do what you want to the webpart property!
for another example you can use this code but its using the webpart ID instead!
now your asking well i can already do that or it doesnt give me access still to the property!? well thats because you need to setup the webpart in question properly to show its properties ;) follow my guide here:
Question about webpart properties
call the public accessor e.g. myWebPart.MyString
There are other methods that would also save alot of time and alot of code! e.g
when you build the webpart that you want to ammend (its properties) you can go to build folder and add that DLL into the webpart that will be changing the properties and than you have direct access to properties ;)!
This is a method that i would use as its far less code! no looping though webpart manager ect! no fuss!
use this as a guide if you dont know how!
dont forget to also add the dll into the GAC (assembly folder)
1) get the webpart you want to ammend (dll)
2) open the new webpart that will be changing the webpart above
3) add reference to that dll (follow guide in link above)
4) code, use the methods class ect ;)
5) build webpart add to sharepoint ect
6) add dll from first webpart into GAC