static void Main(string[] args) { //This example returns an item called "Test Item" from the Announcements list //For your own lists, first add a Service Reference to the SharePoint site you want to query //Then change the item object below. //Formulate the URL to the List Data RESTful service string Url = "http://intranet.contoso.com/_vti_bin/listdata.svc"; //Create a dataContext object for the service TeamSiteDataContext dataContext = new TeamSiteDataContext(new Uri(Url)); //Authenticate as the currently logged on user dataContext.Credentials = CredentialCache.DefaultCredentials; //Query for a single item by using a lambda expression to select items with a specific title AnnouncementsItem item = dataContext.Announcements.Where(i => i.Title == "Test Item").FirstOrDefault(); if (item == null) { //There is no announcement with that title Console.WriteLine("An announcement with the title 'Test Item' was not found."); } else { //Return the item Console.WriteLine("Title: " + item.Title); Console.WriteLine("Body: " + item.Body); } //This line prevents the console disappearing before you can read the result //Alternatively, remove this line a run the project without debugging (CTRL-F5) Console.ReadKey(); }
public bool DeleteItem(string Title) { //This example finds the first item in the Announcements list //with the specified title. //For your own lists, first add a Service Reference to the //SharePoint site you want to query, then change the item object below. //Tell the user what's going on Console.WriteLine("Received a DeleteItem call. About to query SharePoint..."); //Formulate the URL to the List Data RESTful service. //You must correct this path to point to your own SharePoint farm string Url = "http://intranet.contoso.com/_vti_bin/listdata.svc"; //Create a dataContext object for the service TeamSiteDataContext dataContext = new TeamSiteDataContext(new Uri(Url)); //Authenticate as administrator. NetworkCredential myCredential = new NetworkCredential("Administrator", "pass@word1"); dataContext.Credentials = myCredential; try { //Use a lambda expression to locate an item with a matching title AnnouncementsItem announcement = dataContext.Announcements.Where(i => i.Title == Title).FirstOrDefault(); //Delete the announcement dataContext.DeleteObject(announcement); dataContext.SaveChanges(); return(true); } catch (Exception e) { Console.WriteLine("An error occurred: {0}", e.Message); return(false); } }
public bool InsertItem(string Title, string Body) { //This example inserts a new item into the Announcements list //For your own lists, first add a Service Reference to the //SharePoint site you want to query, then change the item object below. //Tell the user what's going on Console.WriteLine("Received a InsertItem call. About to query SharePoint..."); //Formulate the URL to the List Data RESTful service. //You must correct this path to point to your own SharePoint farm string Url = "http://intranet.contoso.com/_vti_bin/listdata.svc"; //Create a dataContext object for the service TeamSiteDataContext dataContext = new TeamSiteDataContext(new Uri(Url)); //Authenticate as administrator. NetworkCredential myCredential = new NetworkCredential("Administrator", "pass@word1"); dataContext.Credentials = myCredential; //Create a new item AnnouncementsItem newAnnouncement = new AnnouncementsItem(); newAnnouncement.Title = Title; newAnnouncement.Body = Body; try { //Add it to the Announcements list dataContext.AddToAnnouncements(newAnnouncement); dataContext.SaveChanges(); Console.WriteLine("Added this new item: {0}", Title); //Return the dictionary return(true); } catch (Exception e) { Console.WriteLine("An error occurred: {0}", e.Message); return(false); } }
public static AnnouncementsItem CreateAnnouncementsItem(int ID) { AnnouncementsItem announcementsItem = new AnnouncementsItem(); announcementsItem.Id = ID; return announcementsItem; }
public void AddToAnnouncements(AnnouncementsItem announcementsItem) { base.AddObject("Announcements", announcementsItem); }