If we want to fetch data from sharepoint and use it in .net Application(Web App or Win App)
The steps are as under…
- Copy three dll files in the Application
- Microsoft.Sharepoint.dll
- Microsoft.Sharepoint.Client.dll
- Microsoft.Sharepoint.Client.Runtime.dll
- Microsoft.Sharepoint.dll
- Add the reference of these three files to the Application
- Add the function for the Data AccessLayer
(This Code is for getting all categories)
public
ListItemCollection GetAllCategory()
- {
List resultlist = null;
ListItemCollection items = null;
//List<Category> resultList = new List<Category>();
//Category category = null;
try
- {
string webUrl = "http://domain:port";
NetworkCredential credentials = new
NetworkCredential("UserName", "Password", "Domain");
using (var clientContext = new
ClientContext(webUrl))
- {
- clientContext.Credentials = credentials;
- resultlist = clientContext.Web.Lists.GetByTitle("Categories");
StringBuilder query = new
StringBuilder();
- query.Append("<View />");
CamlQuery caml = new
CamlQuery();
- caml.ViewXml = query.ToString();
- items = resultlist.GetItems(caml);
- clientContext.Load(items);
- clientContext.ExecuteQuery();
- }
- }
catch (Exception exception)
- {
Console.WriteLine(exception.Message);
- }
return items;
- }
- Add the function for the Business Layer
(This Code is for getting all categories)
- public
List<Category> GetAllCategory()
- {
List<Category> lstctg = new
List<Category>();
CategoryDataAccess CDA = new
CategoryDataAccess();
try
- {
ListItemCollection lst = CDA.GetAllCategory();
foreach(ListItem item in lst)
- {
Category ct = new
Category();
- ct.CategoryId = item.Id;
- ct.Description = item["Description"].ToString();
- ct.Title = item["Title"].ToString();
- lstctg.Add(ct);
- }
return lstctg;
- }
catch (Exception ex)
- {
throw ex;
- }
- }
- public
- This will generate the List of Entities(Category) and return to the view Layer
- This functions explain how to set the authority for the sharepoint site.