Ravi Kumar

Ravi Kumar

  • 1.6k
  • 192
  • 20.4k

Copy/Move documents to another library SharePoint 2013

Jul 13 2015 3:13 AM
Hello,
 
I have written a event receiver code in SharePoint 2013 Item updated event to edit metadata properties of the document and copying\moving it to another library. 
 
It is working for a MS word  & Excel older versions like(.doc , .xls , .txt , .png etc)
It is not working for a MS word & Excel older versions like(.docx , .xlsx) 
 
my code is as below 
 
using (SPSite site = new SPSite("http://yoursiteurl"))
{
using (SPWeb web = site.OpenWeb())
{
 
SPList list = web.Lists["test"];
SPListItem item = properties.ListItem;
//add metadata
Hashtable ht = new Hashtable();
ht.Add("testcol", "myfile");
ht.Add("vti_title", "mytitle");
SPFile destfile = list.RootFolder.Files.Add(item.File.Name, item2.File.OpenBinary(), ht, true);
destfile.update(); 
}
}
 
 
Many thanks in advance
 
Thanks
Ravi Patil 
 
 
 
 

Answers (3)