Copying Page From One Site to Another

Code Snippet that copies a page from one site to another :


// Fetch event data
RadTreeNode sourceNode = NodeEvent.SourceDragNode;
RadTreeNode destNode = NodeEvent.DestDragNode;
// Swap nodes in tree.
if (sourceNode != destNode.Parent)// && sourceNode.Category == "PAGE" && destNode.Category != "PAGE")
{
SPSite DestSite = new SPSite(destNode.ID);
SPWeb DestWeb = DestSite.OpenWeb();
SPSite SourceSite = new SPSite(sourceNode.Attributes["SPWEB"]);
SPWeb SourceWeb = SourceSite.OpenWeb();
SourceWeb.AllowUnsafeUpdates = true;
DestWeb.AllowUnsafeUpdates = true;
SPFile spFileOriginal = SourceWeb.GetFile(sourceNode.ID);
Byte[] binFileOriginal = spFileOriginal.OpenBinary();
string fileNameTarget = "CopyOf" + spFileOriginal.Name;
SPFolder destPagesFolder = DestWeb.GetFolder("Pages");
if (destPagesFolder != null)
{
if (spFileOriginal.CheckOutStatus == SPFile.SPCheckOutStatus.None)
{
spFileOriginal.CheckOut();
}
SPFile spDestFile = destPagesFolder.Files.Add(fileNameTarget, binFileOriginal, true);
SPLimitedWebPartManager wpmOrigin = spFileOriginal.GetLimitedWebPartManager(PersonalizationScope.Shared);
SPLimitedWebPartManager wpmDest = spDestFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in wpmOrigin.WebParts)
{
wpmDest.AddWebPart(wp, wpmOrigin.GetZoneID(wp), wp.ZoneIndex);
}
spFileOriginal.Update();
spFileOriginal.CheckIn("checkin - Page copied to the following location " + spDestFile.Url);
spFileOriginal.Approve("approve - Page copied to the following location ");
spFileOriginal.Publish("Published as well");
spDestFile.CheckIn("Copied version of the original page " + spFileOriginal.Url);
spDestFile.Approve("Copied version of the original page " + spFileOriginal.Url);
spDestFile.Publish("Copied version of the original page " + spFileOriginal.Url);
}
destNode.AddNode(sourceNode);
}
// Expand destination node to see result of swap immediately.
destNode.Expanded = true;
// Clear last active selection.

Comments

Anonymous said…
わたしは元気です。ありがとう。 [url=http://ci2s.org/viagura.htm]バイアグラ 服用[/url] バイアグラ 服用

Popular posts from this blog

Linksys Wireless Connection Failure

The security validation for this page is invalid. Click Back in your Web

Access Denied Host Header Sharepoint 2010 Windows Server 2008 R2