Could anybody help me to get List Item by unique Id in SharePoint without using List? I know the List Item unique Id, but I haven't information about List. Using Client Object Model I can do the following:
using (SP.ClientContext clientContext = new SP.ClientContext(...))
{
**SP.List list = clientContext.Web.Lists.GetById(listId);**
SP.ListItem listItem = list.GetItemById(listItemId);
clientContext.Load(listItem);
clientContext.ExecuteQuery();
...
}
Unfortunately, in this code I use listId, but the problem is that in my task I don't know listId, I have only ListItem Guid. Since I have unique Id, I believe that there must be a way to get this Item without using any additional information.
Find List GUID from SharePoint Web User Interface: Head on to List settings >> Hover over list settings links such as “Column Default Value Settings”, watch the status bar, There is your ID! You can copy shortcut to get the GUID of the particular list!
How do I get the list item ID from the SharePoint Online list? Open the SharePoint Online list that contains the item. At the top of any column, select the down arrow, then select Column settings > Show/hide columns. In the Edit view columns pane that is displayed, select the ID check box and click Apply.
Reading GUID of the current view in Browser's Dev Console Simply, select it in the function and press enter, you'll see details inside. And you can simply read the id like you read an attribute.
An internal ID number used in the database. The GUID element generates a globally unique identifier (GUID) as returned by the Microsoft Component Object Model (COM) function CoCreateGuid.
You've posted a snippet with a Client Object Model, so I suppose it's a preffered object model for the solution. However, if it's acceptable for You, I've found some information on how to achieve this using server side object model, which You may find helpful.
It seems that this can be done using SPWeb.GetFile(Guid itemGuid)
if the item exist in the root site.
If you want it to work also for subsites, you can use SPWeb.GetSiteData method to invoke caml retrieving an item as explained in this article: http://www.chakkaradeep.com/post/Retrieving-an-Item-from-the-RootWeb-and-Subwebs-using-its-UniqueId.aspx.
You can also take a look at this thread on SO for some additional information: SharePoint: Get SPListItem by Unique ID.
If you have any issues using those methods, let me know. I'll also look for alternatives for this to run with Client Object Model and I'll post them if I find some, however, it seems to be more difficult to achieve.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With