Thursday, 14 July 2011

Copy the Items from Top Level Site Document Library to Sub Site Document Libtrary through Event Receiver

 public override void ItemUpdated(SPItemEventProperties properties)
       {
           base.ItemUpdated(properties);
           try
           {
               if (properties.List.Title == "SorceLibrary")
               {
                   {
                       SPSite site1 = new SPSite("http://sharepoint:4747/");
                       SPWeb web1 = site1.OpenWeb();
                       SPListItem myitem = properties.ListItem;
                       if (myitem.File != null)
                       {
                           //string libName = "DestLibrary";
                           SPSite site = new SPSite("http://sharepoint:4747/Products/");
                           SPWeb web = site.OpenWeb();
                           web.AllowUnsafeUpdates = true;
                           // Copy the document to the library
                           SPFolder library = web.Folders["DestLibrary"];
                           library.Files.Add(myitem.Name, myitem.File.OpenBinary());
                           library.Update();
                           web.AllowUnsafeUpdates = false;
                       }

                   }
               }
 }
           catch (Exception exe)
           {
               throw (exe);
           }
          
       }

    }

No comments:

Post a Comment