Hi,
I am trying to copy all pages from one pages library (Say Sub-site A) to Pages library in another Sub-site (say Sub-site B). both sub-sites are created with Publishing feature enabled. I can Copy the file one-by-one from the UI (using the Copy option inManage Content and Structure).
But since I want to avoid the manual approach, I am using a console application and I get the error that the "Folder "Pages" does not exist." even though I can see and navigate to the pages in it.
Here is my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace CopyPagesToSubsite
{
class Program
{
static void Main(string[] args)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
CopyPagesToSubsite();
});
}
private static void CopyPagesToSubsite()
{
using (SPSite site = new SPSite("http://sp2010"))
{
using (SPWeb web = site.OpenWeb("/En/KISR/TC/"))
{
SPFileCollection collFile = web.GetFolder("Pages").Files;
foreach (SPFile file in collFile)
{
string _fileUrl = "http://sp2010/EN/KISR/TC01/Pages/" + file.Name;
file.CopyTo(_fileUrl, true);//Error is on this line
file.CheckIn("copied from tc", SPCheckinType.MajorCheckIn);
file.Publish("copied from tc");
Console.WriteLine(file.Name + " is copied successfully");
}
}
Console.ReadLine();
}
}
}
}
Any idea what I am doing wrong?
Rgds,
SSP