Click here to Skip to main content
15,888,340 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I will need your help. our project requires to display and download the documents from sharepoint into MVC 4.0. I have tried several blogs and tried to hit some code which is having the namespaces issue as the namespaces are missing.

Also would like help to how can I download these files from Sharepoint to local machine using the MVC 4.0 code.


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.IdentityModel;
using System.IdentityModel;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Client;
using System.Diagnostics;

namespace CommunityArchives.Web.Controllers
{
    public class SharePointIntegrationController : Controller
    {
        //
        // GET: /SharePointIntegration/

        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";
            List<string> documentTitles = new List<string>();
            using (ClientContext context = new ClientContext("http://it/development/Shared%20Documents/Forms/AllItems.aspx"))
            {
                List list = context.Web.Lists.GetByTitle("doctest");
                context.Load(list);
                CamlQuery query = new CamlQuery();
                query.ViewXml = "<View/>";
                ListItemCollection listItems = list.GetItems(query);
                context.Load(list);
                context.Load(listItems);
                //context.Load(listItems ,items => items.Include(
                //    item=>item["FileLeafRef"] 
                //    ));
                context.ExecuteQuery();
                foreach (ListItem item in listItems)
                {
                    documentTitles.Add(item["FileLeafRef"].ToString());
                }
            }
            return View(documentTitles);
        }

    }
}
Posted
Comments
Jameel VM 11-Jun-13 1:45am    
what is the problem you have face?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900