When I use ClientContext context = new ClientContext("SITEURL"); in my event receiver, the event doesn't trigger at all. So my question is can I use managed client object model in event receivers.

When doc created event occurs, I want to copy the document from the document library to a new doc library in a new farm using managed client object model. is this possible or do I have to use ECMA.

Any help is greatly appreciated. Thanks.

  • 2
    Why do you want to use the managed client object model in an event reciever? The code is already running on the sharepoint server, so you're better off just using the Server Object Model Commented Apr 11, 2012 at 19:21
  • The problem is he is moving it to another farm. Commented Apr 11, 2012 at 19:33

2 Answers 2


I was working on sandbox solution, and didn't realize sandbox solutions have limitations. When I tried as farm solution, managed object model works just fine in event receiver. for more info http://msdn.microsoft.com/en-us/library/ee536577.aspx thanks for the reply guys.


You can accomplish this using WebClient PUT. In this example filePath represents the path to the file in question. And fileName was taken from properties.ListItem.File.Name.

When I did this I downloaded the file to the local file system and then deleted it after the operation succeeded. There might be a more efficient way to do that, but it worked fine given my requirements. The users creating the documents in question did not have access to the remote farm.

string _userName = "remoteUserName";
string _password = "SuperSecurePassword";
string _domain = "domain";
remoteFileURL = "http://www.domain.com/LibraryPath/" + fileName;

WebClient webclient = new WebClient();
webclient.Credentials = new NetworkCredential(_userName, _password, _domain);
webclient.UploadFile(remoteFileURL, "PUT", filePath);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.