Как отобразить элементы SP Online Document Library в Grid View и загрузить документ с помощью CSOM - PullRequest
0 голосов
/ 26 марта 2019

В размещенном в приложении SharePoint я хочу отобразить документы онлайн-библиотеки документов SharePoint с метаданными в Gridview. После нажатия на это имя документа в виде сетки, я хочу загрузить документы. Как отобразить элементы SP Online Document Library в сетке Просмотр и загрузка документа с использованием кода CSOM.

Невозможно привязать Listitemcollection к gridview, когда Autogenerate столбцы имеет значение False. Это ошибка. Заголовок и другие поля не найдены.

Попробовал связать это Таблица данных. Но невозможно сделать имя документа гиперссылкой или интерактивным элементом управления

 protected void BtnSearch_Click(object sender, EventArgs e)
    {


        using (var ctx = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), accessToken))
        {

            List<ObjectA> _listA = new List<ObjectA>();

            Web oWebsite = ctx.Web;
            ctx.Load(oWebsite);
            ctx.ExecuteQuery();
            ctx.Load(oWebsite.CurrentUser);
            ctx.ExecuteQuery();

            // To Get Site Tile
            string strtitle = ctx.Web.Title;
            // To Getcurrent logged user
            string strlog = ctx.Web.CurrentUser.LoginName;

            List list = oWebsite.Lists.GetByTitle("Sampledocuments");   //.GetById(new Guid("ebe2bc9e-4f04-46fb-9a41-5baf16c1da57"));
            var q = new CamlQuery() { ViewXml = "<View><Query><Where><And><Eq><FieldRef Name='Account_x002d_Name' /><Value Type='Text'>data</Value></Eq><Eq><FieldRef Name='SalesForce_x002d_ID' /><Value Type='Text'>daat</Value></Eq></And></Where></Query></View>" };
            Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(q);
          //  Microsoft.SharePoint.Client.ListItemCollection it = list.GetItems(q);

            ctx.Load(list);

            ctx.Load(items);
            ctx.ExecuteQuery();





            DataTable dt = new DataTable();



            dt.Columns.Add("Item ID", typeof(int));
            dt.Columns.Add("Item Title", typeof(string));
            dt.Columns.Add("Account Name", typeof(string));
            dt.Columns.Add("Sales Force ID", typeof(string));
            dt.Columns.Add("URL", typeof(string));
            dt.Columns.Add("FileRef", typeof(string));
            dt.Columns.Add("FileDirRef", typeof(string));


                foreach (Microsoft.SharePoint.Client.ListItem item in items)
                {
                    DataRow dr = dt.NewRow();
                    dr["Item ID"] = item["ID"];
                    dr["Item Title"] = item["Title"] != null ? item["Title"].ToString() : "";
                    dr["Account Name"] = item["Account_x002d_Name"] != null ? item["Account_x002d_Name"].ToString() : "";
                    dr["Sales Force ID"] = item["SalesForce_x002d_ID"] != null ? item["SalesForce_x002d_ID"].ToString() : "";
                    dr["URL"] = item["FileLeafRef"] != null ? item["FileLeafRef"].ToString() : "";
                    dr["FileRef"] = item["FileRef"] != null ? item["FileRef"].ToString() : "";
                    dr["FileDirRef"] = item["FileDirRef"] != null ? item["FileDirRef"].ToString() : "";
                  //  FileLeafRef FileRef   FileDirRef
                    dt.Rows.Add(dr);
                }


                GV.DataSource = dt;
                GV.DataBind();
...