7

I was querying a SharePoint library, trying to retrieve some file attributes. Apparently some things like FileType and Date are not supported, even though those fields are listed as a built in field. How do I know what is supported and what isn't? It's a runtime error that I'd like to avoid.

    private static void ListDocuments(ClientContext clientContext)
    {
        List list = clientContext.Web.Lists.GetByTitle("My Documents");

        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml =
            @"<View>
            <Query/>
            <RowLimit>100</RowLimit>
          </View>";
        ListItemCollection listItems = list.GetItems(camlQuery);
        clientContext.Load(
             listItems,
             items => items
                 .Include(
                   // how do I know what is legal here?
                   item => item["LinkFilename"],
                     item => item["FileRef"],
                     item => item["File_x0020_Size"],
                     item => item["File_x0020_Type"],
                     item => item["Modified"]
                     ));
     }
3
  • Why do you say that some attributes are not supported? Commented Apr 22, 2011 at 22:52
  • because I requested "Date" and an exception was thrown when I executed the query. I got the exception: "Column 'Date' does not exist. It may have been deleted by another user. " Commented Apr 22, 2011 at 22:59
  • 1
    If you are looking for the date the item was created, it's internal name is "Created" just like the modify date is "Modified". Commented Apr 23, 2011 at 6:39

5 Answers 5

4

Double check that you are using the internal name for the field you want to query. This has gotten me more than once. Here is a good article that goes over a few ways to check this:

1
  • Thanks! +1. Btw, with SharePoint 2010 Management Shell, you can prune the PS script, replacing two first rows with $web=Get-SPWeb http://mysite. Commented Apr 23, 2011 at 22:29
3

The following code will query the server for the available fields and print them to the console window

        ClientContext clientContext = new ClientContext(URL);
        List list = clientContext.Web.Lists.GetByTitle(Documents);
        FieldCollection fields = list.Fields;  
        clientContext.Load(fields);

        clientContext.ExecuteQuery();

        foreach (Field field in fields)
        {
            System.Diagnostics.Trace.WriteLine("");
            System.Diagnostics.Trace.WriteLine("Title\t\t\t" + field.Title);
            System.Diagnostics.Trace.WriteLine("InternalName\t" + field.InternalName);
            System.Diagnostics.Trace.WriteLine("Scope\t\t\t" + field.Scope);
            System.Diagnostics.Trace.WriteLine("StaticName\t\t" + field.StaticName);
        }
1

In addition to the owesome article, which Abe Miessler has posted:

In fact, all the OOTB SharePoint fields have their Guids in SPBuiltInFieldId class, but their Titles are not always refer to their property names in this class. So, how to determine, which SPBuiltInFieldId member corresponds your concrete field?

Here is an article, which provides full list of Guids, field titles and corresponding SPBuiltInFieldId member names:

http://aarebrot.net/blog/2008/07/frodes-awesome-list-of-sharepoint-column-field-ids-for-sharepoint-2007/

(you can even download xls/csv version of this list)

1

I have used the U2U CAML Query Builder in the past which gives you a list of fields and helps you build the query and test the results. In 2010 I have mainly used linq to SharePoint for querying data, however I have used the following method as well and it worked great

http://ranaictiu-technicalblog.blogspot.com/2011/01/u2u-caml-query-builder-for-sharepoint.html

0

Well I cannot be sure which field objects get initiated when we execute any query or object, its really frustrating but I am used to now. Here's my one of my queries that will initiate all item fields, however to retrieve you would need to know the internal name of the field you want to extract.

items = context.LoadQuery(collListItem.Include
                                                (
                                                item => item.File.ListItemAllFields,
                                                item => item.FileSystemObjectType,
                                                item => item.Id,                     
                                                item => item.File,
                                                item => item.File.ServerRelativeUrl,
                                                item => item.DisplayName
                                                 ).Where(item => item.Id > id && item.FileSystemObjectType == FileSystemObjectType.File)); 

hope this helps.

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.