Click here to Skip to main content
15,936,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a SharePoint job to read a list.....

I managed to do the job but I can't find a way to access the list within the job...

Can anyone help me? Thanks in advance!
Posted
Updated 10-Mar-10 9:39am
v2

1 solution

C#
SPWebApplication webApp = this.WebApplication;
SPSite site = this.WebApplication.Sites["SiteName"];
SPWeb web = site.OpenWeb("webUrl");  //  or site.RootWeb;
SPList list = web.Lists["ListName"];

foreach (SPListItem item in list.Items)
{
    //  If you know what fields you want, you can try the below
    object fieldValue = item["FieldName"];

    //  If you want to loop over all fields of an item
    foreach (SPField field in item.Fields)
    {
        object fieldValue2 = item[field.Id];

        //  Do whatever you want with field values
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900