Setting “Created by” field with CSOM

Are you dreaming setting the Author (Created by) of a Sharepoint record when you insert a new item thru CSOM access ?
Something like

ListItemCreationInformation wCreation = new ListItemCreationInformation();
 Microsoft.SharePoint.Client.ListItem wItem = wSPList.AddItem(wCreation);
 wItem["Title"] = "nothing special";
 wItem["Author"] = "test";
 wItem.Update();
 wCT.ExecuteQuery();

where “test” is a user different from the one you are connected with.
If you try that, you’ll get an error about a “readonly” field.

You know or can get the user ID (e.g. 28)… just code :

 ListItemCreationInformation wCreation = new ListItemCreationInformation();
 Microsoft.SharePoint.Client.ListItem wItem = wSPList.AddItem(wCreation);
 wItem["Title"] = "nothing special";
 wItem["Author"] = 28;
 wItem.Update();
 wCT.ExecuteQuery();

and That works …
Isn’t CSOM awesome ?

Sharepoint Migrated sites 2010->2013 miss the “quick edit” button

A migrated site SP2010->SP2013 gets in trouble with the Quick Edit button, not showing in the SP 2010 Custom lists.

If you create a new list, it works… but not in an existing list.
In fact, it is a Microsoft Sharepoint bug in the views.
This can be corrected by adding clienttemplates.js in JSLinks in the view.
You can do that with SP Designer… or you can develop a piece of code which adds that to all the views of all the lists I you site.

Here is i.e. a piece of code achieving the job.

static void UpdateWebViews(String iWeb)
        {
            SPWeb wWeb = new SPSite(iWeb).OpenWeb();
            Console.WriteLine();
            Console.WriteLine(wWeb.Url);
            wWeb.AllowUnsafeUpdates = true;
            List wlView = new List();
            foreach (SPList wList in wWeb.Lists)
                try
                {
                        foreach (SPView wView in wList.Views) try
                            {
                                if (String.IsNullOrEmpty(wView.JSLink))
                                    wlView.Add(wView);
                            }
                            catch { }
                }
                catch (Exception wE)
                {
                    try { Console.WriteLine("Can't reach list " + wList.Title + " : " + wE.Message); }
                    catch { }
                }

            foreach (SPView wView in wlView)
                try
                {
                    wView.JSLink = "clienttemplates.js";
                    wView.Update();
                    Console.WriteLine("View " + wView.ParentList.Title + "." + wView.Title + " updated.");
                }
                catch (Exception wE)
                {
                    try { Console.WriteLine("Can't change view " + wView.ParentList.Title + "." + wView.Title + " : " + wE.Message); }
                    catch { }
                }
        }
 

The full Console application requesting site or web update and url and doing the job can be requested, free of charge to gilbert.nicolet@bpa-solutions.net

O365 SharePoint problems when changing fields in an OOB ContentType

Changing the fields of a ContentType with fields to remove, new fields to add and reordering them seem easy.

E.g.

  1. Load the ContentType and its fields (+executequery)
  2. Delete all FieldLinks
  3. Add the fields you want with something like
     wCT.FieldLinks.Add(new FieldLinkCreationInformation() { Field = “MyField” });  
  4. Update ContentType and List (+ExecuteQuery)
    Works fine on normal ContentTypes.

Read more

CSOM & CursorPosition

When reading CSOM ListItem Collection, we are used to work with the PagingInfo tag that we assign to the Query. ListItemCollectionPosition.

GetItems returns the “next page” tag in same field Query. ListItemCollectionPosition.PagingInfo.

So, page after page, you scroll thru the entire list.

Up to now (July 7th, 2015), when we arrive at the end of the List, Query. ListItemCollectionPosition returned an empty PaginInfo. BUT, now, it returns the same tag that passed to launch the retrieve.

Workaround : save the paginginfo you give to the Query.ListItemCollectionPosition.PagingInfo and compare it to the received Query. ListItemCollectionPosition.Paginginfo. If it’s the same, you are at the end of the list.