none
how to reference a sharepoint list in your code using c#

Answers

  • Hi Ramanjulu,

    I have used the below code and its working fine without giving the internal name for the column. Can you check the display name of the columns are correct.

                using (SPSite site = new SPSite("http://xxxxxx/sites/home/"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists["Test"];
                        SPListItem item1 = list.GetItemByIdSelectedFields(3, "Title", "Test Column");
                    }
                }

    Thanks,
    Dhileep


    Tuesday, August 07, 2012 4:36 AM

All replies

  • Hi Ramanjulu,

    Please see the below sample codes to access the SharePoint list using both Server Object Model and Client Object Model.

    Server Object Model if the c# application runs in the server itself:

    using(SPSite site = new SPSite("site url"))
    {
      using(SPWeb web = site.OpenWeb())
      {
        SPList list = web.Lists["ListName"];
        Console.WriteLine(list.Title);
      }
    }

    Client Object Model if the application is running outside of the server:

    ClientContext context = new ClientContext("site url");
    List list = context.Web.Lists.GetByTitle("Tasks");
    context.Load(list);
    context.ExecuteQuery();

    Console.WriteLine(list.Title);

    Reference:
    http://msdn.microsoft.com/en-us/library/ff798388.aspx

    Thanks,
    Dhileep

    Monday, August 06, 2012 1:04 PM
  • thanks for your quick reply sir,

    i am placing my code please find an error in it

    here the error shows "item does not exit", the "item" which is there in fourth line from beginning. can you tell what is the reason and please guide if any changes needs to be done.

    this would be great if you provide me one more info.

    How to create a workflow to trigger a mail by an event receiver when an item is changed or udpated or edited in a list. this is more than enough.

    


    Ramanjulu Naidu N

    Monday, August 06, 2012 1:14 PM
  • Hi,

    You must use Internal Name  .

    Try "Manual_x0020_Selection instead" of "Manual Selection"

    For mail sending : see this thread http://social.msdn.microsoft.com/Forums/eu/sharepointdevelopment/thread/1f0fb6a7-7c0d-4189-b432-b692dc2e1897

    NicoBzh


    Monday, August 06, 2012 1:24 PM
  • Hi Ramanjulu,

    I have used the below code and its working fine without giving the internal name for the column. Can you check the display name of the columns are correct.

                using (SPSite site = new SPSite("http://xxxxxx/sites/home/"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists["Test"];
                        SPListItem item1 = list.GetItemByIdSelectedFields(3, "Title", "Test Column");
                    }
                }

    Thanks,
    Dhileep


    Tuesday, August 07, 2012 4:36 AM