Solved

Rename Document Library Document using Client Object Model

Posted on 2011-03-01
5
2,067 Views
Last Modified: 2012-05-11
Does anyone have and example of renaming a document in a SharePoint 2010 document library and folder using the SharePoint 2010 Client Object Model (Microsoft.SharePoint.Client.File)?

I've tried setting the fields Title, FileRef and FileDirRef to the new name. I've even tried a FIle.MoveTo (which I really don't want to do I just want to rename the file/title).

Thanks,
TK
0
Comment
Question by:tkendall57
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Expert Comment

by:sabby447
ID: 35020433
0
 
LVL 3

Author Comment

by:tkendall57
ID: 35022821
I was hoping for an example using the Microsoft.SharePoint.Client or Microsoft.SharePoint.Silverlight library and not the lower-level Microsoft.SharePoint (which can't be used in Silverlight).

0
 
LVL 1

Accepted Solution

by:
lpd123 earned 500 total points
ID: 35772384
hi i'm using this for renaming, hope it can help you or give you some ideas

cheers
Lars

------Code--
      public Boolean RenameFolder(string siteurl, string groupname, string libname, string RelRoot, string foldername, string newname)
        {

            using (ClientContext clientContext = new ClientContext(siteurl))
            {
                try
                {
                    clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
                    clientContext.FormsAuthenticationLoginInfo = _formsLoginInfo;
                    List oList = clientContext.Web.Lists.GetByTitle(libname);
                    ListItemCollection collListItem;
                    string prefix = ConfigurationManager.AppSettings["FolderPrefix"].ToString();



                    CamlQuery camlQuery = new CamlQuery();
                    // .ViewXml = "<View><RowLimit>100</RowLimit></View>";
                    if (RelRoot != "") RelRoot = "/" + RelRoot;
                    Boolean libdelete = (foldername == libname);

                    if (libdelete)
                    {
                        oList.Title = newname;
                        oList.Update();
                        clientContext.ExecuteQuery();
                        return true;
                    }
                    else
                    {
                        camlQuery.FolderServerRelativeUrl = prefix + groupname + "/" + libname + RelRoot;
                    }
                    collListItem = oList.GetItems(camlQuery);
                    clientContext.Load(collListItem, items => items.IncludeWithDefaultProperties(item => item.DisplayName, item => item.File.ServerRelativeUrl));
                    clientContext.ExecuteQuery();

                    foreach (ListItem _item in collListItem)
                    {
                        if ((_item.FileSystemObjectType == FileSystemObjectType.Folder) && (string.Compare(_item.DisplayName, foldername, true) == 0))
                        {

                            _item["FileLeafRef"] = newname;
                            _item["Title"] = newname;
                            _item.Update();
                            clientContext.ExecuteQuery();
                            TCDebug.DebugFile.PostDebugEvent("Rename folder", "From " + foldername + " to " + newname, DebugFormName, _username);
                            return true;
                        }
                    }

                    return false;
                }
                catch (Exception e)
                {
                    TCDebug.DebugFile.PostDebugEventException("Renamefolder", e.Message, DebugFormName, _username);
                    return false;
                }
            }
        }
0
 
LVL 12

Expert Comment

by:Hairbrush
ID: 37693391
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Scenario: Let’s say you have a quote worksheet in Excel that you use to work up sales figures and such for your clients. You utilize SharePoint to manage and keep track of these documents. You would like values from your worksheet to populate Sh…
Pimping Sharepoint 2007 without Server-Side Code Part 1 One of my biggest frustrations with Sharepoint 2007 in the corporate world is that while good-intentioned managers lock down the more interesting capabilities of Sharepoint programming in…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question