Sharepoint Asp.net Integration using Client

If we want to fetch data from sharepoint and use it in .net Application(Web App or Win App)

The steps are as under…

Earn upto Rs. 9,000 pm checking Emails. Join now!
  1. Copy three dll files in the Application
    1. Microsoft.Sharepoint.dll
    2. Microsoft.Sharepoint.Client.dll
    3. Microsoft.Sharepoint.Client.Runtime.dll
  2. Add the reference of these three files to the Application
  3. Add the function for the Data AccessLayer
    (This Code is for getting all categories)

    1. public
      ListItemCollection GetAllCategory()
    2. {

    3. List resultlist = null;

    4. ListItemCollection items = null;

    5. //List<Category> resultList = new List<Category>();

    6. //Category category = null;

    7. try
    8. {

    9. string webUrl = "http://domain:port";

    10. NetworkCredential credentials = new
      NetworkCredential("UserName", "Password", "Domain");

    11. using (var clientContext = new
      ClientContext(webUrl))
    12. {
    13. clientContext.Credentials = credentials;
    14. resultlist = clientContext.Web.Lists.GetByTitle("Categories");

    15. StringBuilder query = new
      StringBuilder();

    16. query.Append("<View />");

    17. CamlQuery caml = new
      CamlQuery();
    18. caml.ViewXml = query.ToString();

    19. items = resultlist.GetItems(caml);
    20. clientContext.Load(items);
    21. clientContext.ExecuteQuery();
    22. }
    23. }

    24. catch (Exception exception)
    25. {

    26. Console.WriteLine(exception.Message);

    27. }

    28. return items;
    29. }
  4. Add the function for the Business Layer
    (This Code is for getting all categories)
    1. public
      List<Category> GetAllCategory()
    2. {

    3. List<Category> lstctg = new
      List<Category>();

    4. CategoryDataAccess CDA = new
      CategoryDataAccess();

    5. try
    6. {

    7. ListItemCollection lst = CDA.GetAllCategory();


    8. foreach(ListItem item in lst)
    9. {

    10. Category ct = new
      Category();
    11. ct.CategoryId = item.Id;
    12. ct.Description = item["Description"].ToString();
    13. ct.Title = item["Title"].ToString();
    14. lstctg.Add(ct);
    15. }

    16. return lstctg;
    17. }

    18. catch (Exception ex)
    19. {

    20. throw ex;
    21. }
    22. }
  5. This will generate the List of Entities(Category) and return to the view Layer
  6. This functions explain how to set the authority for the sharepoint site.

Search This Blog

Link Within Related Posts Plugin for WordPress, Blogger...