0

This sounds like something easy but I some how can't find an answer. I am trying to get an SPItem from a SharePoint list (the item is a folder) so that I can set certain permissions on the folder using c#. What I have done so fare is:

SPQuery query = new SPQuery();
                        query.Query = "<Where><Eq><FieldRef Name=\"Name\" /><Value Type=\"Text\">Folder Name</Value></Eq></Where>";
                        query.RowLimit = 1;
                        query.ViewFields = "";
                        SPListItemCollection items = documentList.GetItems(query);
                        SPListItem custConfFolder = items[0]

However when the code reaches the last line (items[0]) the following SPException is thrown:

"One or more field types are not installed properly. Go to the list settings page to delete these fields."

In the list the field Name exists and is given as "Folder Name". Do I need to use the internal name of the field if so where can I find the internal name? or is there a completely different way to retrieve this list item?

Thank a lot for any clues

0

try the internal name!

                    SPQuery query = new SPQuery();
                    query.Query = "<Where><Eq><FieldRef Name=\"Name\" /><Value Type=\"Text\">Folder_x0020_Name</Value></Eq></Where>";
                    query.RowLimit = 1;
                    query.ViewFields = "";
                    SPListItemCollection items = documentList.GetItems(query);
                    SPListItem custConfFolder = items[0];

looks like your code is correct but the field is wrong, iv changed 'Folder Name' to Folder_x0020_Name, your right that you have 'Folder Name' but as its a query i have a feeling its looking at the internal name which translates any space as x0020 and in your case threw an error noting that its wrong or doesnt exist.

1

Why are you putting in an empty ViewFields? If you do not want to set it, just remove that line!

                    SPQuery query = new SPQuery();
                    query.Query = "<Where><Eq><FieldRef Name=\"FileLeafRef\" /><Value Type=\"Text\">Folder Name</Value></Eq></Where>";
                    query.RowLimit = 1;
                    SPListItemCollection items = documentList.GetItems(query);
                    SPListItem custConfFolder = items[0]

If you do want to set it you should insert some <FieldRef Name=\"ColumnName\" /> in it

  • Thanks for the reply, I tried removing the ViewFields with the same result as before. – user3297993 May 28 '14 at 8:13
  • See my update about switching Name with the internal field name FileLeafRef – Robert Lindgren May 28 '14 at 8:16
0

Use SPQuery as :

SPQuery query = new SPQuery();
                    query.Query = "<Where><Eq><FieldRef Name=\"FileLeafRef\" /><Value Type=\"Text\">Folder Name</Value></Eq></Where>";
                    query.RowLimit = 0;
                    query.ViewFields = "";
                    query.ViewAttributes = "Scope=\"RecursiveAll\"";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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