Tag Archives: SharePoint list

Using C# to read data from a SharePoint list using the SharePoint REST API

If you’re working with a C# application that is required to read information contained in a SharePoint list located on an external SharePoint farm, the SharePoint REST API can provide just the solution that you’re looking for.  Here is some sample code that you can use for accessing the information contained in that SharePoint list:

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Web.Script.Serialization;

namespace Sample
{
    public class SharePointListReader
    {
        ...

        public List<SharePointListItem> GetAllSPListItems()
        {
            List<SharePointListItem> posts = new List<SharePointListItem>();
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://webapp/site/_api/web/lists/getbytitle('listName')/items?$select=id,Title");
            request.Method = "GET";
            request.Accept = "application/json;odata=verbose";
            request.ContentType = "application/json;odata=verbose";
            request.Credentials = System.Net.CredentialCache.DefaultCredentials;
            WebResponse response = request.GetResponse();
            Data data = null;

            // Read the returned posts into an object that can be consumed by the calling application
            using (response)
            {
                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    try
                    {
                        string jSON = reader.ReadToEnd();
                        data = serializer.Deserialize(jSON);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(string.Format("An error occurred when reading the list items from SharePoint: {0}; {1}", ex.Message, ex.StackTrace));
                    }
                }
            }
            foreach (SharePointListItem post in data.d.results)
            {
                posts.Add(post);
            }
            return posts;
        }
    }

    public class Data
    {
        public Results d { get; set; }
    }

    public class Results
    {
        public SharePointListItem[] results { get; set; }
    }

    public class SharePointListItem
    {
        public string id { get; set; }
        public string Title { get; set; }
    }
}

SharePoint Tasks List plus Project – Better Together

SharePoint tasks lists provide a great way to collaborate and stay up to date on the status of your projects. By using Microsoft Project Professional, you can take your project management to the next level by using more advanced features like scheduling and even create gorgeous and comprehensive reports. In a way, the SharePoint site and its tasks lists are where team members can view and edit the progress of their tasks, and Project Professional is where project managers can manage the progress of their projects. SharePoint tasks list sync empowers you to use the great functionalities of both Project and SharePoint tasks lists, at the same time.

You can create a new SharePoint tasks list that supports tasks with hierarchy, and indent/outdent those tasks while typing them in SharePoint, using the Alt+shift+Right/Left shortcuts. Then, in order to sync this SharePoint tasks list with Project, all you need to do is select the “Open with Project” button in the List tab of the ribbon:

1

This will open your tasks list along with the timeline view in Project Professional and you’ll even be started in a screen that walks you through 3 steps to show you how you can take advantage of the powerful features of Project:

2

And when you switch to the Gantt view, you can see the same tasks list as was in SharePoint:

3

You can continue editing the project plan in Project, and when you hit Save, Project will automatically sync the plan with the SharePoint tasks list, and also save the project file (.mpp) in the Site Assets library of the SharePoint site. Therefore, every time you, or any other project manager, open the project plan, you can view the most recent status of the project. In 2013, we are saving an up to date project file in the Site Assets library so that users won’t have to deal with multiple conflicting or out-of-date project files. Moreover, we have greatly improved the conflict resolution mechanism so we now look for conflicts at the cell-level instead of the task-level.

Accessing and re-opening this project is very easy: if you are in the SharePoint site, you can open the same project plan by selecting the “Open with Project” button. Alternatively, if you already have Project Professional open, you can find this project in the Recent Projects list in the Open tab:

4

Using the SharePoint tasks list feature, you can also convert standalone project plans into SharePoint tasks list and start collaborating with other team members on those plans. For instance, if you are using Project Professional to manage a special launch event, you can now go to the Save As tab of the File menu and create a new project site with an associated SharePoint tasks list:

5

This will create a new Project Site and save the project plan in the Site Assets library of that site. From that point on, you can open this this project plan from the tasks list and keep the tasks list and the project plan in sync.

During the SharePoint tasks list sync, we sync the following fields between your SharePoint list and Project by default: task name, start date, finish (due) date, % Complete, resource name, and predecessors. However, if you want to map more fields to be synced between Project and SharePoint, you can do so in the Info tab of the File menu: open the “Map Fields” dialog, and pick any new fields that you’d like to sync. This way, you can have your team members report on other custom fields, or generate reports based on non-default SharePoint columns.

6

Ref : Office Blogs