In this post I will explained how we can programmatically copy documents from one document library to another.
Firstly create two document library.Then create a Visual studio solution with User Interface as shown below
Add the below code snippet
protected void BtnSave_Click(object sender, EventArgs e)
{
try
{
SPSite oSite = SPContext.Current.Site;
SPWeb oWeb = oSite.RootWeb;
SPFileCollection oFileCol = oWeb.GetFolder(txtSourceLib.Text).Files;
foreach (SPFile oFile in oFileCol)
{
oFile.CopyTo(txtTargetLib.Text + "/" + oFile.Name, true);
}
lblMsg.Text = "sucessfully copied";
}
catch (Exception ex)
{ }
}
Hi, Can you please post code for..
ReplyDeleteif the source and target library are in different site collection? then how the write?
Hi, Can you please post code for..
ReplyDeleteif the source and target library are in different site collection? then how the write?