I used a CAML query to get file information in a document library. In the CAML query I get the GUID in order to get the unique id of the document.

<FieldRef Name='GUID'/>

In a different occasion I tryed to get the file through the GUID using GetFile() method

web.GetFile(new Guid("{the guid from CAML query }"));

It gives an error.

So, retrieved the ID instead

<FieldRef Name='ID'/>

Through the DocumentLibrary, took the SPFile

Guid fileStr = documentsLibrary.Items.GetItemById(int.Parse("The ID from CAML query")).File.UniqueId;
SPFile aa = documentsLibrary.GetItemByUniqueId(fileStr).File;

It works fine. So the two questions i have are:

Are there two GUID's for item and File & Is there a way to directly get the SPFile GUID via CAML, so that it can be used in web.GetFile() ?

1 Answer 1


CAML query returns splistitemcollections. Why don't you get the GUID for the returned items? http://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.splistitem.uniqueid%28v=office.15%29.aspx

  • Or even better just use the .File from the items returned in the collection! Commented Aug 29, 2014 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.