Link to home
Start Free TrialLog in
Avatar of Adnan
AdnanFlag for Norway

asked on

Get sharepoint document library Field/column values

Hi

I have a simple document library and i want to loop threw all my documents and get a specific value from custom field/column i created in my library.

Here is my code:
List docList = context.Web.Lists.GetByTitle("IKSRevisjon");
                    context.Load(docList);

                    CamlQuery camlQuery = new CamlQuery();
                    //camlQuery.ViewXml = "<View Scope='RecursiveAll '></View>";
                    camlQuery.ViewXml = @"<View Scope='RecursiveAll '>
                                    <Query>
                                    </Query>
                                </View>";

                    ListItemCollection listItems = docList.GetItems(camlQuery);
                    context.Load(listItems);
                    context.ExecuteQuery();

                    foreach (ListItem listItem in listItems)
                    {
                        Console.WriteLine("Id: {0} ", listItem.Id);
                        string title = listItem.FieldValues["Created_x0020_By"].ToString();
                        var avd = listItem.FieldValues["Avdeling"].ToString();
                        Console.WriteLine("Title", title);
                        Console.WriteLine("Avdeling", avd);
                    }

Open in new window

i get the value of "Created By":
string title = listItem.FieldValues["Created_x0020_By"].ToString();

Open in new window


but why cant i get value from other fields...?
ASKER CERTIFIED SOLUTION
Avatar of Adnan
Adnan
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Adnan

ASKER

SOLVED...
Avatar of Walter Curtis
Thanks for the info.