Use the SPFile.CopyTo
method.
SPFile.CopyTo Reference
Example:
SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSite.AllWebs["Site_Name/Subsite_Name"])
{
SPFileCollection collFiles = oWebsite.GetFolder("Shared
Documents").Files;
for (int intIndex=0; intIndex<collFiles.Count; intIndex++)
{
collFiles[intIndex].CopyTo("Destination_DocLib/" +
collFiles[intIndex].Name, true);
}
}
You could also use the SPFileCollection.Add
method.
SPFileCollection.Add Reference
Example:
using (SPSite oSiteCollection = new SPSite("http://localhost"))
{
using(SPWeb oWebsite = oSiteCollection.AllWebs["MyWebSite"])
{
SPWebCollection collWebsites = oWebsite.Webs;
SPFile oFile = oWebsite.GetFile("MyDocLib/MyFile");
foreach (SPWeb oWebsiteNext in collWebsites)
{
SPFolder oFolder = oWebsiteNext.GetFolder("Shared Documents");
SPFileCollection collFiles = oFolder.Files;
string strDestUrl = oFolder.Url + "/" + oFile.Name;
byte[] binFile = oFile.OpenBinary();
collFiles.Add(strDestUrl, binFile);
oWebsiteNext.Dispose();
}
}
}