How to Build an MVC Application for SharePoint

Log In to Watch How to Video Now
How to Build an MVC Application for SharePoint

Please log-in to view this video. Sign up for FREE ACCESS HERE

Presenter: Stefano Tempesta, VP Engineering at Turbedo Networks, Australia.

In this video you will learn how to:

1. Write code to perform basic operations with the SharePoint 2013 .NET Framework client-side object model (CSOM).

2. Build an ASP.NET MVC application that retrieves information from a SharePoint server.




Video Transcript:

Hi i’m Stefano Tempesta and I’m a proud member of the European  SharePoint community in this video you will learn how to write code to perform basic operations with a  SharePoint dotnet and client option or the season and build an MVC application that receives information from a  SharePoint site let’s start by creating a new speed of net web application project in Visual Studio give a  SharePoint embassy name and we select the template empty of type embassy as this application will connect to a  SharePoint server we need to reference the system  SharePoint libraries best way to do that is using new gotta add a reference and search for Microsoft or  SharePoint good client and Microsoft or  SharePoint or client got runtime for those of you used to a TD framework accessing  SharePoint can be implemented in a similar way let’s create a  SharePoint contacts class does make it disposable and implement them this possible pattern then all we need to do is to obtain a reference to the  SharePoint client context in the  SharePoint client library all the client contacts need is the URL of the  SharePoint site to which the MVC application is connecting conveniently this URL is tore in the web config and accessible by a static variable inside the  SharePoint context class because client contacts extend the client runtime context which is disposable we need to dispose the  SharePoint contacts properly the MVC application that we want to build connects to a  SharePoint site and displays a discussion list by category for the purpose I’m using a  SharePoint site created with a community template so I have the following list already available categories and discussion lists I also create a new entry in the discussion list by entering subject body question and picking a category we now need our controller for our MVC application we give a name default controller and we add a view for the index action as for anti different work I want to use a  SharePoint context here to access my categories in the index action and the discussion list in the discussion action obviously I still don’t type the categories so I need to define them let’s start creating our first model the category model I add a class I name it category obviously and I enter the properties that identify a category the ID the name and the description the same I do for the discussion but let’s try to remember what are the properties of a discussion so there is a subject there is a body there’s a question which is a boolean value and a category is a drop-down list and here I create my model discussion with a subject a body is question and a category property now I can add my modeled as enumerables to my  SharePoint context and create some private methods for loading categories and discussion lists respectively now that they have my category I can go back to the index action and complete my link expression all the categories by name passing the collection the view and then implementing the view so I define a model as an enumerable of my category and then display the categories as unordered lists I also want to create an action link for each category when clicking on the name of the category I call the discussion action in the default controller passing as a rot value the category name so back to the controller I now introduce the discussion action which accept a category as a input parameter same approach I use the  SharePoint context and retrieve the discussion list from the context the  SharePoint list is now returning me all the discussions for a specific category because I apply again another link filter it’s time now to add the discussion view and I use the list scaffolding template for displaying all the discussions in a table because this is a read-only table I can remove all the actions for editing and modifying the existing discussion list items back to my discussion action I want to improve the readability of the URL of this action by changing too Kassel route and i do so by specifying an attribute and map the attribute route in the route config class we can have a look now to the load categories method in the  SharePoint context more in detail so what we need is to obtain a reference to the web which is the current site in  SharePoint then load the list and execute the query is always important to execute a query on the object to load I can then access the specific list by title and query again all the items in the list using a camel query in a very similar way that load discussion this method exists the context to obtain a reference to the current site then open a list the discussions list by name by title and for each list item then create an instance of our discussion model this is my MVC application running presenting a list of categories and for each category as a click on the category name I see a list of all the discussions available in  SharePoint this is retrieving information in real time directly from the  SharePoint Server and in summary a few tips for integrating your MVC application with  SharePoint load the site from your client contacts first using the combination load and execute query then load the list searching for list by title and after you actually obtain a reference to the list you can access the list properties and for list items is necessary to load again and execute the query against the list item collection the last reference is to the list item properties once the list item collection has been loaded and the query has been executed then all the properties of the list items are accessible and can be used in your code that’s all for this week I hope you’ve enjoyed it and if you have any question please feel free to contact you

Share this on...
Log In

Rate this Post:



Apps SharePoint

You might also like ...