Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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"]
                     ));
     }
share|improve this question
    
Why do you say that some attributes are not supported? –  Abe Miessler Apr 22 '11 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. " –  MedicineMan Apr 22 '11 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". –  JohnnyT Apr 23 '11 at 6:39

5 Answers 5

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:

share|improve this answer
    
Thanks! +1. Btw, with SharePoint 2010 Management Shell, you can prune the PS script, replacing two first rows with $web=Get-SPWeb http://mysite. –  Andrey Markeev Apr 23 '11 at 22:29
up vote 3 down vote accepted

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);
        }
share|improve this answer

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)

share|improve this answer

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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