RE: Programmatically Move Area to a different location

From: Jim H (JimH_at_discussions.microsoft.com)
Date: 11/01/04


Date: Mon, 1 Nov 2004 04:14:07 -0800

Hi Daniel Larson

Thanks a lot. It was very helpful.

Regards

Jim

"Daniel Larson" wrote:

> Jim,
>
> This was actually a bit simpler than I thought it would be. It's as simple
> as setting the Area's ParentID property to the ID of the location you want to
> move it to. DON'T call the RemoveArea() method of the parent area's areas
> collection property, this will delete it. (It actually can demonstrate really
> bad error handling or lack of in the framework though...) Just set the
> ParentID property and you're done.
>
> Also, don't forget to call Update() on the area you move or it won't commit.
>
> Here is the code, assuming you've created an area called "test2" and have
> the "news" area in the default location (tweak it as you need). I did this in
> a console app.
>
> using Microsoft.SharePoint.Portal;
> using Microsoft.SharePoint.Portal.SiteData;
> using Microsoft.SharePoint.Portal.Topology;
> ...
> TopologyManager topologyManager = new TopologyManager();
> Uri uri = new Uri("http://localhost");
>
> SPSite site = new SPSite(uri.ToString());
>
> PortalContext portalContext = PortalApplication.GetContext(site.ID);
> site.Dispose();
>
> Guid homeGuid = AreaManager.GetSystemAreaGuid(portalContext, SystemArea.Home);
> Area homeArea = AreaManager.GetArea(portalContext, homeGuid);
>
> Area test = subareas["test2"];
> Area news = subareas["news"];
>
> test.ParentID = news.ID;
> test.Update();
>
> -Daniel Larson
>
>
> "Jim H" wrote:
>
> > Hi All,
> >
> > I wanted to move an Area programmatically from one location to the other
> > without deleting and recreating it.
> > I wanted to move one area under AreaGroup1 to AreaGroup2.
> > Please let me know.
> >
> > Thanks in advance,
> >
> > Regards
> >
> > Jim H



Relevant Pages