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.
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.
Related
I can't get my head around this.
If I have a ContentType called Contacts. The ContentType has two fields attached to it.
FirstName (textfield) and LastName (textfield).
If I want to create a new contentitem of this type then I can write code like this.
dynamic contact = _services.ContentManager.New("Contacts");
contact.Contacts.FirstName.Value = "John";
contact.Contacts.LastName.Value = "Doe";
_services.ContentManager.Create(contact, VersionOptions.Published);
This does not work. The Contentitem gets created but the fields are empty.
However, if I write it like this it works. Why is that? Must I set the fields values after ContentManager.Create is called?
dynamic contact = _services.ContentManager.New("Contacts");
_services.ContentManager.Create(contact, VersionOptions.Published);
contact.Contacts.FirstName.Value = "John";
contact.Contacts.LastName.Value = "Doe";
What you observed is indeed the intended behaviour and is by design. I've come across this before too and also created an issue about it. As you can see there it was closed by Sebastien, the lead developer stating that this is by design but unfortunately not explaining why.
FYI the standard workflow for managing content items is the following:
Instantiate item.
Create it.
Update its values.
If the update happened through the model binder then check if the ModelState is valid. If not, cancel the transaction and return.
If everything's OK and the content type is set to be draftable, publish the item.
You can see an explained example of this in the Orchard Training Demo module (ContentsAdminController.PersonListDashboardPost()).
I have an odd issue.
I have client that wants a sharepoint list what is populated from a WCFService. That part is working quite well.
I have a bdcmodel that is mapping the WCF data and I can create an external list from the bdcmodel as well so that is working fine.
The issue I have is that one of the properties in the model is actually a collection of entities called Attributes. The objects in this collection simply have 2 properties Name and Value so really they are just a key value pair.
The client wants to see the list of attributes of the parent entity in the external list. So there would be an Attributes column and within that column would be the list of attributes for each parent object.
Is there even a way to do this? I am looking into Custom Field Types, but it seems like these are really intended to be singular values.
How would I create a list within and external list?
Any help anyone can give would be great even if its just to tell me that there really isn't a stable way to do this so I can go back to the client and tell them we will need to build a custom list to support this because the OOB external list and custom fields and custom field types won't support this kind of nested listing.
I decided to set up the custom field as a string and when I get my collection in from the BdcModel I am serializing it to JSON and then passing it to the field. When the field is viewed in display, edit or new I have overridden the FieldRenderingControl and I am tiling the collection out that way.
I have a list of 6000 listitem GUIDs. I need to check if each item still exist on the Web.
Previously, I was using the SPWeb.GetFile(GUID) method to check the item.
But now I need to convert that process usinig the ClientObjectModel. I cannot find a way to retrieve the item using the GUID.
I even tried from the "List" object. And can't find a way to retrieve the item from its GUID neither.
Please help! :(
Try to use CAML Query.
Ex CAML Query:
<Query><Where><Eq><FieldRef Name='ID'/><Value type='Counter'>"+fileIDtoFind+"</Value></Eq></Where></Query>
For more details see: http://msdn.microsoft.com/en-us/library/ie/ee857094.aspx
I have a sharepoint site which contains site and subsite and document libraries in it. Couple of document library has setting to maintain the versioning of the doc along with the comments.
Now I have requirment where a client wants to see this settings site wise as, under which site how meny doc libraries are there which have versioning enabled...?
I want to show this information as an report.
Do I need to write a custom webPart or code for it ? Or how can I show this information as a report in sharepoint.
Thanks in advance.
Sachin
Versioning information is a property of the SPList class even though only document libraries can use versioning in SharePoint.
How you output this is up to you but here is some quick code to get you started.
Use the SPWeb.GetListsOfTypeMethod(SPBaseType.SPDocumentLibrary) to return an SPListCollection, loop through the list collection checking for the SPList.EnableVersioning property.
//Get your SPWeb whichever way works best
SPListCollection lists = web.GetListsofType(SPDocumentLibrary);
foreach (SPList list in lists)
{
if(list.EnableVersioning = true)
{
// Write to a list or update a count
}
//Output count results or a list of the doc libraries
}
Cheers, CJ
I want to get a list of documents which are in Shared Documents (this is the Document Library). I am using the GetListItems web service.
I am getting response with list of rows. But I don't see a word document which is created under that. Am I doing something wrong?
The GetListItems method does not return actual documents, it returns the ListItem information (metadata). It should include a Url (FileRef / FileLeafRef) property you can use to download the documents by looping through the method's result.