Get current loggedin user using silverlight client object model SharePoint 2010?

Hello,
How can i get the current loged in user of sharepoint 2010 in silverlight4.XX  version by programtically in C#?
Thanks
Lovkesh Patel

Hi,
ClientContext clientContext = ClientContext.Current;
clientContext.Load(clientContext.Web, s => s.CurrentUser);
clientContext.ExecuteQueryAsync((sender, args) => {
var currentUser = clientContext.Web.CurrentUser; }, null);
For more information:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.web.currentuser.aspx and
http://stackoverflow.com/questions/3441794/retrieve-current-user-login-in-sharepoint-from-a-silverlight-application
Hope this helps you
Senior Sharepoint Developer,STS [email protected]

Similar Messages

  • Cannot download master page using managed client object model SharePoint 2010

    string siteUrl = "http://server:port/sites/demo";
    string fileServerRelativeUrl = @"/sites/demo/_catalogs/masterpage/v4.master";
    using (ClientContext context = new ClientContext(siteUrl)){ FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, fileServerRelativeUrl);}
    File.OpenBinaryDirect() throws "The remote server returned an error: (404) Not Found" error. while Microsoft.SharePoint.Client.File f1 = web.GetFileByServerRelativeUrl(fileUrl);
                    context.Load(f1);
                    context.ExecuteQuery();this gives the file object.File.OpenBinaryDirect() works if I pass "/sites/demo/_catalogs/masterpage/TabViewPageLayout.aspx" as fileServerRelativeUrl.Both the files are present in Master Page Gallery.File.OpenBinaryDirect() doesn't work if I pass any of ".master" file in the master page galleryPlease let me know whether downloading the master pages is supported using managed Client object model. 

    Hi,
    If don't change the default config, We are unble to download master page.
    It's better to create your own (perhaps based on the default.master) and use that master page.
    also,make sure there's no a permission issue on the website.
    Thanks
    Guangchao chen
    TechNet Community Support

  • Get current item id using JavaScript Client Object Model

    I have a client query that query SharePoint list Items. Lets say it is a document library. I need to get the list item id of each. 
    I can query the Title of the document using this syntax.
    ctx.CurrentItem['Title']
    But when I try 
    ctx.CurrentItem['ID']
    for list item ID, it does not give a value. How can I solve this?

    Hi Malin,
    If you're using the JavaScript Client Object Model, try using the SPListItem.get_item('key') method as in the example below:
    <script>
    ExecuteOrDelayUntilScriptLoaded(function(){
    var arrIds = [];
    var clientContext = new SP.ClientContext();
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query></Query></View>');
    var items = clientContext.get_web().get_lists().getByTitle("Your List Title Here").getItems(camlQuery);
    clientContext.load(items);
    clientContext.executeQueryAsync(Function.createDelegate(this,function(){
    var itemEnumerator = items.getEnumerator();
    while(itemEnumerator.moveNext()){
    var itemId = itemEnumerator.get_current().get_item('ID');
    arrIds.push(itemId);
    alert(arrIds);
    }), Function.createDelegate(this, function(){
    alert("something went wrong");
    },"SP.js");
    </script>

  • Client Object Model Sharepoint 2010

    We are using client object model in sharepoint 2010
    When we excute the ExcuteQuery method of clinet obejct model we are getting following error
    The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again
    Girish

    Hi ,
    A FormDigest control has to be included to create a digest for security validations when performing some modifications to SharePoint data. It adds a security token inside your page based on user, site and time. Once the page is posted back the security token
    is validated. Once the security token is generated it’s valid for a configurable amount of time. 
    for more info check the below links
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.formdigest.aspx
    http://ranaictiu-technicalblog.blogspot.com.au/2010/02/sharepoint-2010-client-object-model-for.html
    if above link is not working, use below function before execute the query.
    function CustomUpdateFormDigest()
    if(window._spPageContextInfo != null)
    var $v_2 = window._spPageContextInfo;
    var $v_3 = $v_2.webServerRelativeUrl;
    var $v_4 = window._spFormDigestRefreshInterval;
    UpdateFormDigest($v_3, $v_4);
    CustomUpdateFormDigest();
    Please mark it as an answer/helpful if it is useful.
    Thanks
    Mahesh

  • How to access SharePoint External Data column using Silverlight Client Object Model

    Hi Friends,
    I have one sharepoint list which has column of type External Data type. My need is to access each item and get the values from the External Data Type column field.
    Can anyone help me how to acheive this. I am begineer in Silverlight.
    Thanks, Cool Developer

    Hi Friends,
    I have one sharepoint list which has column of type External Data type. My need is to access each item and get the values from the External Data Type column field.
    Can anyone help me how to acheive this. I am begineer in Silverlight.
    Thanks,
    RajanThanks, Cool Developer

  • CAML Query to get specific item in folder based on dropdown value using Javascript client object model

    Hi,
    I am using the Javascript Client object model.
    I have a custom list and a custom document library.
    Custom list contains 2 columns - dlName , dlValue
    The document library contains 2 folders - "folder1" ,  "folder2" and contains some images.
    The image name starts with the "dlValue" available in the custom list
    I am using a visual webpart and using javascript client object model.
    I am trying to achieve the below functionality:
    1) Load a dropdown with the custom list.
    2) set the image based on the value in dropdown.
    I have achieved the first option, I have set the dropdown, but not sure how to query the folder and set the image.
    Below is the code i have used so far:
    //In Visual webpart
    <select id="ddlTest" >
    </select>
    <br/>
    <div id="PreviewLayer">
    <img id="imgPlaceHolder" runat="server" alt="Image" title="imgPlaceHolder" src=" " />
    </div>
    // In Javascript file
    function RenderHtmlOnSuccess() {
    var ddlTest = this.document.getElementById("ddlTest");
    ddlTest.options.length = 0;
    var enumerator = this.customListItems.getEnumerator();
    while (enumerator.moveNext()) {
    var currentItem = enumerator.get_current();
    var dropdownValue = currentItem.get_item("dlValue");
    ddlTest.options[ddlTest.options.length] = new Option(currentItem.get_item("dlName"), dropdownValue);
    setImage(dropdownValue); // Not sure how to query the folder and set the image based on value.
    // Also if dropdown value is changed, corresponding image should be shown
    How to query the folder and based on dropdown value, show the image? Also, how to handle the dropdown value change?
    Thanks

    Hi,
    Here are two links for your reference:
    Example of how to Get Files from a Folder using Ecmascript \ Javascript client object model in SharePoint 2010
    http://sharepointmantra.wordpress.com/2013/10/19/example-of-how-to-get-files-from-a-folder-using-ecmascript-javascript-client-object-model-in-sharepoint-2010/
    SP2010 JSOM Client Object Model: How to get all documents in libraries including all folders recursively
    http://sharepoint.stackexchange.com/questions/70185/sp2010-jsom-client-object-model-how-to-get-all-documents-in-libraries-including
    In SharePoint 2013, we can also use REST API to achieve it.
    http://msdn.microsoft.com/en-us/magazine/dn198245.aspx
    Thanks,
    Dennis Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Dennis Guo
    TechNet Community Support

  • SharePoint 2013 implement simple logout button which do not redirect to default sign out page using JavaScript client object model

    I am using windows authentication in my web application.
    My requirement is to implement a sign out button which will sign out the user without having him to close the browser and application should not ask him to login again.
    I tried following two options:
     1. Redirecting the user to default signout.aspx page " /_layouts/15/SignOut.aspx "
     2. Using "Sign In as a different user" URL " /_layouts/15/closeConnection.aspx?loginasanotheruser=true "
    In first case, user is redirected to default sign out page but he can press "Go Back to Site" link to revisit the site. Another major issue is that the user has to close the browser to sign out from the application completely, which is not desirable
    in my project requirement.
    In second case, the the current user is signed out of the application but if the user has saved the password in browser, he gets signed in automatically to the application.
    I also came across the solution where we replace the default sign out page with a custom sign out page, but I am not sure whether it can be implemented using JavaScript Client Object Model of SharePoint.

    Hi 
    I'm basically looking for the exact answer for the query.
    Meanwhile you need to go through the link mentioned below in order to understand how to do it.
    Debugging and Logging Capabilities in SharePoint 2010
    Indul Hassan
    Microsoft Community Contributor
    http://www.indulhassan.com
    You Snooze.. You Lose !!

  • Add multiple people using Javascript Client Object Model

    I am trying to add multiple people to a SP column of type Person/Group i.e. people picker. I am able
    to add one successfully using their userId, but HAVE no clue how to do that for multiple people. Here is the code for one user:
    function UserDrop(e, toElement, listGuid, columnName) {
    //EcmaScript Client Object Model
    var ctx = new SP.ClientContext.get_current();
    var list = ctx.get_web().get_lists().getById(listGuid);
    var item = list.getItemById(elementId);
    //columnName is of type person/group and I am adding user //whose userId is 7
    item.set_item(columnName, 7);
    item.update();
    // asynchronous call
    ctx.executeQueryAsync(
    function () { toElement.innerHTML = userLinkHtml; },
    function () {alert ("Error")}
    return false;
    This works great and I can add user whose userId is 7, however I want to add multiple people like let's say users of user Ids 7 and 8. 
    Any ideas or help will be greatly appreciated. 
    There is a thread on this one but that's from .net COM which could accessed here: http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/5183e87c-ee1d-4594-9492-0dfdf6616cce
    7929

    Hi ,
    Can somebody let me know how the same(assigning the array values to lookup value field) can be achieved with multi-select lookup value. SP.FieldLookUpValue do not have any such methods like fromUser. Please help. Please find my code block below
    clientContext = new SP.ClientContext.get_current();
    if (this.clientContext != undefined && clientContext != null) {
    var webSite = clientContext.get_web();
    oList = webSite.get_lists().getByTitle("Add New User");
    $.urlParam = function(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    return results[1] || 0;
    var itemid = parseInt($.urlParam('ID'));
    var item = oList.getItemById(itemid);
    var users = new Array();
    users.push(SP.FieldLookupValue.set_lookupId(1));
    users.push(SP.FieldLookupValue.set_lookupId(2));
    item.set_item('Responsibility', users);
    item.update();
    clientContext.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
    also i cant use managed client object model.. so pls let me know how to achieve the same using javascript client object model
    Ranjani.R

  • Add attachments to List Item using JavaScript Client object model in SP2010

    Hi All ,
    I have created custom form for submitng data in list using javascript client object model/jquery .
    Now I want to add option to uplaod multiple attachments to that list item also .
    Is there option with client object model for uplaoding attachment.
    Thanks
    M
    Manesh G

    Can you try this and let me know
    using (SPSite _site = new SPSite(SPContext.Current.Site.Url))
        using (SPWeb _web = _site.OpenWeb())
         //Let's suppose your Item Id is 1
         int ItemId = 1;
         SPList  oList = _web.Lists["EmployeeList"];
         SPListItem  _item = oList.GetItemById(ItemId);
         if (FileUpload1.HasFile)
               _web.AllowUnsafeUpdates = true;
              Stream fs = FileUpload1.PostedFile.InputStream;
              byte[] _bytes = new byte[fs.Length];
              fs.Position= 0;
              fs.Read(_bytes, 0, (int)fs.Length);
              fs.Close();
              fs.Dispose();
              _item.Attachments.Add(FileUpload1.PostedFile.FileName, _bytes);
              _item.Update();
              _web.AllowUnsafeUpdates = false;

  • Read versions of comments field using javascript client object model

    Hi,
     Does someone knows how to Read versions  of comments field in 'tasks' list using javascript client object model?
    Thanks
    Manvir

    Hi,
    According to your description, I know you want to read versions of comments field.
    We can use the
    SPServices to achieve it. The below code for your reference:
    $().SPServices({
    operation: "GetVersionCollection",
    async: false,
    strlistID: "tester",
    strlistItemID: 1,
    strFieldName: "comments",
    completefunc: function (xData, Status) {
    $(xData.responseText).find("Version").each(function(i) {
    console.log("Name: " + $(this).attr("Information") + " Modified: " + $(this).attr("Modified"));
    More information:
    http://spservices.codeplex.com/releases/view/81401
    Best Regards,
    Dennis Guo

  • Error in Application.Run(DisplayLoginForm) and Remote Authentication in SharePoint Online Using the Client Object Model

    Hi guys
    I Think that is a simple error, but I don’t have enough knowledge in .NET apps.
    I make an console app that use Remote Authentication in SharePoint Online Using the Client Object Model, that a I downloaded from MSDN.
    This App run ok.
    But when I like to make a Windows From App. This component send me an error in Application.Run(DisplayLoginForm)
    This err msg :
     An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
    Additional information: Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead.
    Is there any way to use a form inside a windows form?
    Thank in advance
    Ramiro
    Ramiro B

    Hi,
    Based on the error message, please do as following:
    1. Check your code logic below:
    void btn_Click(object sender, System.EventArgs e)
    Thread t = new Thread(StartMyForm);
    t.TrySetApartmentState(ApartmentState.STA);
    t.Start();
    public static void StartMyForm()
    Application.Run(new MyForm(..));
    2.Try to add the following code line in your code.
    Application.Restart();
    If the issue still exists, please provide your requirement and code for a further research.
    Best Regards
    Dennis Guo
    TechNet Community Support

  • How I can send emails using the client object model?

    I have tried this, but I always get an exception with error message "A recipient must be specified.":
    string webUrl = "http://sharepoint.example.com/";
    EmailProperties properties = new EmailProperties();
    properties.To = new string[] { "[email protected]" };
    properties.Subject = "Test subject";
    properties.Body = "Test body";
    ClientContext context = new ClientContext(webUrl);
    Utility.SendEmail(context, properties);
    context.ExecuteQuery(); // ServerException thrown here
    context.Dispose();
    Server stack trace:
    at System.Net.Mail.SmtpClient.Send(MailMessage message)
    at Microsoft.SharePoint.Utilities.SPUtility.SendEmail_Client(EmailProperties properties)
    at Microsoft.SharePoint.ServerStub.Utilities.SPUtilityServerStub.InvokeStaticMethod(String methodName, XmlNodeList xmlargs, ProxyContext proxyContext, Boolean& isVoid)
    at Microsoft.SharePoint.Client.ServerStub.InvokeStaticMethodWithMonitoredScope(String methodName, XmlNodeList args, ProxyContext proxyContext, Boolean& isVoid)
    at Microsoft.SharePoint.Client.ClientMethodsProcessor.InvokeStaticMethod(String typeId, String methodName, XmlNodeList xmlargs, Boolean& isVoid)
    at Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessStaticMethod(XmlElement xe)
    at Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessOne(XmlElement xe)
    at Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessStatements(XmlNode xe)
    at Microsoft.SharePoint.Client.ClientMethodsProcessor.Process()
    msdn link: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.utilities.utility.sendemail.aspx

    hi
    if you will check the code of SendEmail_Client(EmailProperties properties), you will find that it may only send emails to internal users. May be it was made intentionally in order to prevent spamming from client code. So let's see:
    internal static void SendEmail_Client(EmailProperties properties)
    if (properties.To.Count == 0)
    throw new SPException(SPResource.GetString(web.LanguageCulture, "SendEmailInvalidRecipients", new object[0]));
    AddressReader func = null;
    using (MailMessage mm = new MailMessage())
    func = delegate (MailAddress a) {
    mm.To.Add(a);
    ResolveAddressesForEmail(web, properties.To, func);
    new SmtpClient(SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address).Send(mm);
    I.e. it adds recipient in ResolveAddressesForEmail() method. Now let's check this method:
    private static void ResolveAddressesForEmail(SPWeb web, IEnumerable<string> addresses, AddressReader func)
    if (addresses != null)
    foreach (string str in addresses)
    if (string.IsNullOrEmpty(str))
    continue;
    SPPrincipalInfo info = ResolvePrincipal(web, str, SPPrincipalType.All, SPPrincipalSource.All, null, false);
    if ((info != null) && (info.PrincipalId > 0))
    if (!string.IsNullOrEmpty(info.Email))
    try
    func(new MailAddress(info.Email, (info.DisplayName != null) ? info.DisplayName : "", Encoding.UTF8));
    catch (FormatException)
    continue;
    if ((string.IsNullOrEmpty(info.Email) && info.IsSharePointGroup) && web.DoesUserHavePermissions(SPBasePermissions.BrowseUserInfo))
    SPGroup byNameNoThrow = web.SiteGroups.GetByNameNoThrow(info.LoginName);
    if (byNameNoThrow == null)
    continue;
    foreach (SPUser user in byNameNoThrow.Users)
    if (!string.IsNullOrEmpty(user.Email))
    try
    func(new MailAddress(user.Email, (user.Name != null) ? user.Name : "", Encoding.UTF8));
    continue;
    catch (FormatException)
    continue;
    continue;
    I.e. at first it tries to resolve user using ResolvePrincipal() method. If it is not resolved (info == null) email is not sent. But if it is - it first checks that email is not empty. If it is not - it adds email to the MailMessage.To recipients list. If
    it is empty it checks whether the principal info represents Sharepoint group. If yes - it will send email to each member of the group.
    So it may be so that you try to send email to external user (which is not supported according to the code above), or resolved principal doesn't have email specified.
    Blog - http://sadomovalex.blogspot.com
    CAML via C# - http://camlex.codeplex.com

  • How to hide ribbon but show welcome control for all users using security trimmed control in sharepoint 2010

    Hi All,
    I have a requirement to hide ribbon in a document library for the read permission users. I have applied SPSecurityTrimmedControl, it is working for the read permission user but for the whole site it is hiding and also unable to see the welcome control,
    like user name, sign in as different user, etc.,
    <Sharepoint:SPSecurityTrimmedControl runat="server" ID="spTrimRibbon" PermissionMode="All" Permissions="ManageLists">
    I want to apply SPSecurityTrimmedControl to specific list/library with welcome control. Can someone please help me here.
    I Appreciate your assistance...
    MercuryMan

    Hello MercuryMan,
    I guess you have applied your code in master page that's why it is hidden from site. To hide specific list ribbon, go to your list-->and edit the page-->then add content editor webpart and apply below script.
    <SharePoint:SPSecurityTrimmedControl PermissionsString="ManagePermissions" runat="server">
    <div id="s4-ribbonrow" class="s4-pr s4-ribbonrowhidetitle">
    </div>
    </SharePoint:SPSecurityTrimmedControl>
    http://blogs.msdn.com/b/sharepointdev/archive/2012/04/30/how-to-hide-the-ribbon-in-sharepoint-2010-rajeswari-mohandas.aspx
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Value does not fall within expected range in client object model SharePoint online

    Hi,
    I might be missing something, at least i hope so because I don't see it anymore.
    Yes, I used the search, and yes many had the same error, but I think my problem has to be something else.
    It is not size related but more context related i think.
    I've build a function to break inheritance on folders and libraries for several document librarys to implement a crud matrix.
    The thing is, it works sort of. The function takes a list and foldername. If the foldername is null the
    inheritance on the list is broken and the group is given the roles as provided.
    If a foldername is given, i retrieve the folder, break the inheritance and set the new permissions for the given group.
    The problem is: The second time the function is called with a foldername it breaks on the getItems for querying the folder.
    It is not folder related, becaus changing the folder order gives the same problem on another folder.
    I already tried creating a new clientcontext and a new list variable but i cant get it to work.
    I cant get into the server logs because im querying SharePoint Online.
    var list = GetList(clientContext, "Listx");
    AddPermission(list, null, company_Groups.Beheerder, RoleType.Contributor, clientContext);
    AddPermission(list, null, company_Groups.Projectleider, RoleType.Contributor, clientContext);
    AddPermission(list, null, company_Groups.Constructeur, RoleType.Reader, clientContext);
    AddPermission(list, null, company_Groups.Tekenaar, RoleType.Contributor, clientContext);
    //Montagepartner
    AddPermission(list, "Folder2", company_Groups.Montagepartner, RoleType.None, clientContext);
    AddPermission(list, "Folder1", company_Groups.Montagepartner, RoleType.None, clientContext);         <----- is where it breaks
    AddPermission(list, "Folder3", company_Groups.Montagepartner, RoleType.None, clientContext);
    AddPermission(list, "Folder4", company_Groups.Montagepartner, RoleType.None, clientContext);
    private void AddPermission(List list, string folderName, company_Groups group, RoleType roleType, ClientContext clientContext)
    //MsOnlineClaimsHelper claimsHelper = new MsOnlineClaimsHelper();
    //using (ClientContext clientContext = new ClientContext(ctx.Url))
    //clientContext.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;
    //clientContext.RequestTimeout = timeOut;
    if (!list.HasUniqueRoleAssignments)
    list.BreakRoleInheritance(false, true);
    list.Update();
    var principal = GetPrincipal(clientContext, group.ToString());
    var role = GetRole(clientContext, roleType);
    // Add the role to the collection.
    //var collRdb = new RoleDefinitionBindingCollection(clientContext) { role };
    if (folderName != null)
    var query = new CamlQuery();
    query.ViewXml = "<View Scope=\"RecursiveAll\"> " +
     "<Query>" +
      "<Where>" +
      "<And>" +
    "<Eq>" +
      "<FieldRef Name=\"FSObjType\" />" +
      "<Value Type=\"Integer\">1</Value>" +
    "</Eq>" +
    "<Eq>" +
      "<FieldRef Name=\"Title\"/>" +
      "<Value Type=\"Text\">" + folderName + "</Value>" +
    "</Eq>" +
      "</And>" +
      "</Where>" +
      "</Query>" +
      "</View>";
    // query.FolderServerRelativeUrl = Path.Combine(list.RootFolder.ServerRelativeUrl, folderName);
    ///This is where it breaks, the second time the function executes on a list with another folder name
    var folderItems = list.GetItems(query);    <----- is where it breaks 
    clientContext.Load(folderItems);
    clientContext.ExecuteQuery();
    ListItem folder = null;
    if (folderItems.Count > 0)
    folder = folderItems[0];
    folder = list.GetItemById(folder.Id);
    //if (!folder.HasUniqueRoleAssignments)
    folder.BreakRoleInheritance(true, true);
    folder.Update();
    RoleDefinition roledef = clientContext.Web.RoleDefinitions.GetByType(roleType);
    RoleDefinitionBindingCollection roleDefCol = new RoleDefinitionBindingCollection(clientContext);
    // .Add(roledef);
    roleDefCol.Add(roledef);
    folder.RoleAssignments.Add(principal, roleDefCol);
    folder.Update();
    else
    RoleDefinition roledef = clientContext.Web.RoleDefinitions.GetByType(roleType);
    RoleDefinitionBindingCollection roleDefCol = new RoleDefinitionBindingCollection(clientContext);
    // .Add(roledef);
    roleDefCol.Add(roledef);
    list.RoleAssignments.Add(principal, roleDefCol);
    list.Update();
    clientContext.ExecuteQuery();

    Hi,                                                             
    What if you execute the AddPermission method once a time, will the error still occur or can your code works out the expected result?
    As the program breaks in the GetItems() method, to narrow down this issue, I suggest to comment the other lines of code which has no relationship with the items retrieving, then debug your project to see whether the error will
    still occur.
    Best regards
    Patrick Liang
    TechNet Community Support

  • Rename a File in a SharePoint document library through Client object model

    Hi,
    How  to Rename a File in a SharePoint document library through Client object model?
    Thanks
    Poomani Sankaran

    Hi,
    According to your description, you want to rename file in the document library using SharePoint Client Object Model.
    Here is a code snippet works well in my environment for your reference:
    static void Main(string[] args)
    string url = "http://sp2013sps/sites/test/";
    ClientContext clientContext = new ClientContext(url);
    Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("Documents");
    clientContext.Load(spList);
    clientContext.ExecuteQuery();
    if (spList != null && spList.ItemCount > 0)
    Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml =@"<View> <Query> <Where><Eq><FieldRef Name='LinkFilenameNoMenu' /><Value Type='Computed'>New Microsoft Word Document.docx </Value></Eq></Where> </Query> <ViewFields><FieldRef Name='Title' /></ViewFields> </View>";
    ListItemCollection listItems = spList.GetItems(camlQuery);
    clientContext.Load(listItems);
    clientContext.ExecuteQuery();
    listItems[0]["Title"] = "word.docx";
    listItems[0]["FileLeafRef"] = "word.docx";
    listItems[0].Update();
    clientContext.ExecuteQuery();
    More information about SharePoint Client Object Model:
    http://msdn.microsoft.com/en-us/library/office/ee537247(v=office.14).aspx
    http://www.codeproject.com/Articles/399156/SharePoint-Client-Object-Model-Introduction
    http://www.learningsharepoint.com/2010/07/12/programmatically-upload-document-using-client-object-model-sharepoint-2010/
    Best regards

Maybe you are looking for