Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
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 –  AndrewSwerlick Apr 11 '12 at 19:21
    
The problem is he is moving it to another farm. –  Robert Kaucher Apr 11 '12 at 19:33

2 Answers 2

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);
webclient.Dispose();
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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