예제 #1
0
        /// <summary>
        /// This method will return a ClientContext object with the authentication cookie set.
        /// The ClientContext should be disposed of as any other IDisposable
        /// </summary>
        /// <param name="targetSiteUrl"></param>
        /// <returns></returns>
        public static ClientContext GetAuthenticatedContext(string targetSiteUrl, int popUpWidth, int popUpHeight)
        {
            CookieCollection cookies = null;

            cookies = ClaimClientContext.GetAuthenticatedCookies(targetSiteUrl, popUpWidth, popUpHeight);
            if (cookies == null)
            {
                return(null);
            }

            ClientContext context = new ClientContext(targetSiteUrl);

            try
            {
                context.ExecutingWebRequest += delegate(object sender, WebRequestEventArgs e)
                {
                    e.WebRequestExecutor.WebRequest.CookieContainer = new CookieContainer();
                    foreach (Cookie cookie in cookies)
                    {
                        e.WebRequestExecutor.WebRequest.CookieContainer.Add(cookie);
                    }
                };
            }
            catch
            {
                if (context != null)
                {
                    context.Dispose();
                }
                throw;
            }

            return(context);
        }
예제 #2
0
        // Populate CBO Drop-down Via SP Online
        private void PopulateSiteListViaO365()
        {
            try
            {
                cboSourceSiteList.Items.Clear();
                cboDestSiteList.Items.Clear();

                using (SPOnlineContext = ClaimClientContext.GetAuthenticatedContext(cboSiteURL.SelectedItem.ToString()))
                {
                    if (SPOnlineContext != null)
                    {
                        //Get the site
                        Web site = SPOnlineContext.Web;
                        SPOnlineContext.Load(site);
                        //Get Lists
                        SPOnlineContext.Load(site.Lists);
                        // Execute
                        SPOnlineContext.ExecuteQuery();

                        foreach (List list in site.Lists)
                        {
                            // Adds List Name to comboBoxes
                            cboSourceSiteList.Items.Add(list.Title);
                            cboDestSiteList.Items.Add(list.Title);
                        }

                        cboSourceSiteList.SelectedIndex = 0;
                        cboDestSiteList.SelectedIndex   = 0;

                        // Clear DGV DataSource
                        sourceDGV.DataSource      = null;
                        destinationDGV.DataSource = null;
                        lblSrcListitemsCountAmt.ResetText();
                        lblDestListitemsCountAmt.ResetText();
                    } // END IF
                }     // END USING
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
예제 #3
0
        // Delete Method via Criteria
        private void DeletionProcessCriteria()
        {
            if (cboSiteList.SelectedItem.ToString().Contains("Archive"))
            {
                MessageBox.Show("Cannot delete items from an archive list.");
            }

            else
            {
                try
                {
                    // ***************************** SP ONLINE LIST(S) ***********************************
                    if (IsSPOnline == true)
                    {
                        SPOnlineContext = ClaimClientContext.GetAuthenticatedContext(cboSiteURL.SelectedItem.ToString());
                        SP.List selectedList = SPOnlineContext.Web.Lists.GetByTitle(cboSiteList.SelectedItem.ToString());

                        CamlQuery camlQuery = new CamlQuery();
                        camlQuery.ViewXml = "<View>" +
                                            "<Query>" +
                                            "<Where>" +
                                            "<And>" +
                                            "<Geq>" +
                                            "<FieldRef Name='From' />" +
                                            "<Value Type='DateTime'>2017-01-01</Value>" +
                                            "</Geq>" +
                                            "<Leq>" +
                                            "<FieldRef Name='From' />" +
                                            "<Value Type='DateTime'>2017-12-31</Value>" +
                                            "</Leq>" +
                                            "</And>" +
                                            "</Where>" +
                                            "</Query>" +
                                            "</View>";

                        ListItemCollection oListitemCollection = selectedList.GetItems(camlQuery);
                        SPOnlineContext.Load(oListitemCollection);
                        SPOnlineContext.ExecuteQuery();

                        int listCount = oListitemCollection.Count;

                        foreach (ListItem sourceListItem in oListitemCollection)
                        {
                            SP.List destinationList = SPOnlineContext.Web.Lists.GetByTitle(cboSiteList.SelectedItem.ToString());

                            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                            ListItem destinationListItem = destinationList.AddItem(itemCreateInfo);

                            switch (cboSiteList.SelectedItem.ToString())
                            {
                            case "All Grant Submitssss":

                                for (int i = 0; i < listCount; i++)
                                {
                                    var item = oListitemCollection[i]; // In order to prevent changes in all places inside the [for loop]
                                    item.DeleteObject();
                                    listCount--;                       // Here, as I am removing 1 item, I am decrementing the count
                                    i--;

                                    // Executes the clientContext.ExecuteQuery() inside the loop to prevent the
                                    // 'The request uses too many resources' error.
                                    selectedList.Update();
                                    SPOnlineContext.ExecuteQuery();

                                    //MessageBox.Show("Deletion in Progress ...");
                                }

                                selectedList.Update();
                                SPOnlineContext.ExecuteQuery();
                                //int endCount = oListitemCollection.Count;

                                break;
                            }// END Switch
                        }

                        MessageBox.Show("Deletion Completed!");
                    }

                    else
                    {
                        // ***************************** SP ON-PREM LIST(S) ***********************************
                        // SP ON PREM Selections
                        SPOnPremContext = new ClientContext(cboSiteURL.SelectedItem.ToString());
                        SP.List selectedList = SPOnPremContext.Web.Lists.GetByTitle(cboSiteList.SelectedItem.ToString());

                        string fromDate = metroDateTimeFrom.Value.ToString("yyyy-MM-dd");
                        string toDate   = metroDateTimeTo.Value.ToString("yyyy-MM-dd");

                        // The following example displays the Items Created less than or earlier to 20XX
                        // This CAMLQUERY is used for ClockInOutLog List
                        CamlQuery camlQuery = new CamlQuery();
                        camlQuery.ViewXml = "<View><Query><Where><Lt><FieldRef Name='Created'/>" +
                                            "<Value Type='DateTime'>" + fromDate + "</Value></Lt></Where></Query><RowLimit>200</RowLimit></View>";

                        ListItemCollection oListitemCollection = selectedList.GetItems(camlQuery);
                        SPOnPremContext.Load(oListitemCollection);
                        SPOnPremContext.ExecuteQuery();

                        int listCount = oListitemCollection.Count;

                        foreach (ListItem sourceListItem in oListitemCollection)
                        {
                            SP.List destinationList = SPOnPremContext.Web.Lists.GetByTitle(cboSiteList.SelectedItem.ToString());

                            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                            ListItem destinationListItem = destinationList.AddItem(itemCreateInfo);

                            switch (cboSiteList.SelectedItem.ToString())
                            {
                            case "ClockInOutLog":

                                for (int i = 0; i < listCount; i++)
                                {
                                    var item = oListitemCollection[i]; // In order to prevent changes in all places inside the [for loop]
                                    item.DeleteObject();
                                    listCount--;                       // Here, as I am removing 1 item, I am decrementing the count
                                    i--;

                                    // Executes the clientContext.ExecuteQuery() inside the loop to prevent the
                                    // 'The request uses too many resources' error.
                                    selectedList.Update();
                                    SPOnPremContext.ExecuteQuery();

                                    //MessageBox.Show("Deletion in Progress ...");
                                    //TODO: Need Progressbar here
                                }

                                selectedList.Update();
                                SPOnPremContext.ExecuteQuery();
                                //int endCount = oListitemCollection.Count;

                                break;

                            case "TrackEmployeeTasks":

                                for (int i = 0; i < listCount; i++)
                                {
                                    var item = oListitemCollection[i]; // In order to prevent changes in all places inside the [for loop]
                                    item.DeleteObject();
                                    listCount--;                       // Here, as I am removing 1 item, I am decrementing the count
                                    i--;

                                    // Executes the clientContext.ExecuteQuery() inside the loop to prevent the
                                    // 'The request uses too many resources' error.
                                    selectedList.Update();
                                    SPOnPremContext.ExecuteQuery();

                                    //MessageBox.Show("Deletion in Progress ...");
                                    //TODO: Need Progressbar here
                                }

                                selectedList.Update();
                                SPOnPremContext.ExecuteQuery();

                                break;
                            }// END Switch
                        }

                        MessageBox.Show("Deletion Completed!");

                        // Populate DGV - Refresh!!
                        PopulateDGV();
                    }
                }
                catch (Exception ex)
                {
                    ex.Message.ToString();
                    MessageBox.Show("Error Encountered " + ex.Message);
                }
            }
        }
예제 #4
0
        // Delete Method
        private void DeletionProcess()
        {
            if (cboSiteList.SelectedItem.ToString().Contains("Archive"))
            {
                MessageBox.Show("Cannot delete items from an archive list.");
            }

            else
            {
                try
                {
                    if (IsSPOnline == true)
                    {
                        SPOnlineContext = ClaimClientContext.GetAuthenticatedContext(cboSiteURL.SelectedItem.ToString());
                        SP.List selectedList = SPOnlineContext.Web.Lists.GetByTitle(cboSiteList.SelectedItem.ToString());

                        CamlQuery camlQuery = new CamlQuery();
                        camlQuery.ViewXml = @"";

                        ListItemCollection oListitemCollection = selectedList.GetItems(camlQuery);
                        SPOnlineContext.Load(oListitemCollection);
                        SPOnlineContext.ExecuteQuery();

                        int listCount = oListitemCollection.Count;

                        foreach (ListItem sourceListItem in oListitemCollection)
                        {
                            SP.List destinationList = SPOnlineContext.Web.Lists.GetByTitle(cboSiteList.SelectedItem.ToString());

                            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                            ListItem destinationListItem = destinationList.AddItem(itemCreateInfo);

                            switch (cboSiteList.SelectedItem.ToString())
                            {
                            case "All Grant Submitssss":

                                for (int i = 0; i < listCount; i++)
                                {
                                    var item = oListitemCollection[i]; // In order to prevent changes in all places inside the [for loop]
                                    item.DeleteObject();
                                    listCount--;                       // Here, as I am removing 1 item, I am decrementing the count
                                    i--;

                                    // Executes the clientContext.ExecuteQuery() inside the loop to prevent the
                                    // 'The request uses too many resources' error.
                                    selectedList.Update();
                                    SPOnlineContext.ExecuteQuery();

                                    //MessageBox.Show("Deletion in Progress ...");
                                }

                                selectedList.Update();
                                SPOnlineContext.ExecuteQuery();
                                //int endCount = oListitemCollection.Count;

                                break;
                            }// END Switch
                        }

                        MessageBox.Show("Deletion Completed!");

                        // Populate DGV - Refresh!!
                        PopulateDGV();
                    }

                    else
                    {
                        // SP ON PREM Selections
                        SPOnPremContext = new ClientContext(cboSiteURL.SelectedItem.ToString());
                        SP.List selectedList = SPOnPremContext.Web.Lists.GetByTitle(cboSiteList.SelectedItem.ToString());

                        CamlQuery camlQuery = new CamlQuery();
                        camlQuery.ViewXml = @"";

                        ListItemCollection oListitemCollection = selectedList.GetItems(camlQuery);
                        SPOnPremContext.Load(oListitemCollection);
                        SPOnPremContext.ExecuteQuery();

                        int listCount = oListitemCollection.Count;

                        foreach (ListItem sourceListItem in oListitemCollection)
                        {
                            SP.List destinationList = SPOnPremContext.Web.Lists.GetByTitle(cboSiteList.SelectedItem.ToString());

                            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                            ListItem destinationListItem = destinationList.AddItem(itemCreateInfo);

                            switch (cboSiteList.SelectedItem.ToString())
                            {
                            case "CADD Office Leave Calendar":

                                for (int i = 0; i < listCount; i++)
                                {
                                    var item = oListitemCollection[i]; // In order to prevent changes in all places inside the [for loop]
                                    item.DeleteObject();
                                    listCount--;                       // Here, as I am removing 1 item, I am decrementing the count
                                    i--;

                                    // Executes the clientContext.ExecuteQuery() inside the loop to prevent the
                                    // 'The request uses too many resources' error.
                                    selectedList.Update();
                                    SPOnPremContext.ExecuteQuery();

                                    //MessageBox.Show("Deletion in Progress ...");
                                    //TODO: Need Progressbar here
                                }

                                selectedList.Update();
                                SPOnPremContext.ExecuteQuery();
                                //int endCount = oListitemCollection.Count;

                                break;
                            }// END Switch
                        }

                        MessageBox.Show("Deletion Completed!");

                        // Populate DGV - Refresh!!
                        PopulateDGV();
                    }
                }
                catch (Exception ex)
                {
                    ex.Message.ToString();
                    MessageBox.Show("Error Encountered " + ex.Message);
                }
            }
        }
예제 #5
0
        // Populate DataGridview
        private void PopulateDGV()
        {
            try
            {
                // ******************** POPULATE DATAGRIDVIEW VIA SP ON-PREM ***************************

                if (IsSPOnline == false)
                {
                    List      list  = SPOnPremContext.Web.Lists.GetByTitle(cboSiteList.SelectedItem.ToString());
                    CamlQuery query = new CamlQuery();
                    query.ViewXml = "<View/>";
                    ListItemCollection items = list.GetItems(query);

                    SPOnPremContext.Load(list);
                    SPOnPremContext.Load(items);

                    SPOnPremContext.ExecuteQuery();

                    string selectedList = cboSiteList.SelectedItem.ToString();

                    switch (selectedList)
                    {
                    default:
                        DataTable table = new DataTable();
                        table.Columns.Add("Title");

                        foreach (ListItem item in items)
                        {
                            table.Rows.Add(item["Title"]);
                        }

                        // Bind data to datagridView
                        listDataDGV.DataSource    = table;
                        lblListitemsCountAmt.Text = items.Count.ToString();

                        break;

                    case "ClockInOutLog":
                        // Show the data
                        DataTable tableCIOLog = new DataTable();
                        tableCIOLog.Columns.Add("Title");
                        tableCIOLog.Columns.Add("Status");
                        tableCIOLog.Columns.Add("Time");
                        tableCIOLog.Columns.Add("Notes");

                        foreach (ListItem item in items)
                        {
                            tableCIOLog.Rows.Add(item["Title"], item["Status"], item["Time"], item["Notes"]);
                        }

                        // Bind data to datagridView
                        listDataDGV.DataSource = tableCIOLog;
                        listDataDGV.AutoResizeColumns();                                            // Resize the DataGridView columns to fit the newly loaded data.
                        listDataDGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; // Columns automatically adjust their widths when the data changes.
                        lblListitemsCountAmt.Text       = items.Count.ToString();

                        break;

                    case "Leave Requests":
                        // Show the data
                        DataTable tableLR = new DataTable();
                        tableLR.Columns.Add("Request For");
                        tableLR.Columns.Add("Title");
                        tableLR.Columns.Add("Status");
                        tableLR.Columns.Add("Leave Code");
                        tableLR.Columns.Add("From");
                        tableLR.Columns.Add("To");
                        tableLR.Columns.Add("Requested Hours");
                        tableLR.Columns.Add("Notes");

                        foreach (ListItem item in items)
                        {
                            try
                            {
                                if (((FieldUserValue)item["Request_x0020_For"]).LookupValue.ToString() != null)
                                {
                                    tableLR.Rows.Add(((FieldUserValue)item["Request_x0020_For"]).LookupValue, item["Title"], item["Status"],
                                                     ((FieldLookupValue)item["Leave_x0020_Code"]).LookupValue, item["From"], item["To"],
                                                     item["Requested_x0020_Hours"], item["Notes"]);
                                }

                                else
                                {
                                    string missingNameValue = "Missing Name";
                                    tableLR.Rows.Add(missingNameValue, item["Title"], item["Status"],
                                                     ((FieldLookupValue)item["Leave_x0020_Code"]).LookupValue, item["From"], item["To"],
                                                     item["Requested_x0020_Hours"], item["Notes"]);
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }

                        // Bind data to datagridView
                        listDataDGV.DataSource = tableLR;
                        listDataDGV.AutoResizeColumns();                                            // Resize the DataGridView columns to fit the newly loaded data.
                        listDataDGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; // Columns automatically adjust their widths when the data changes.
                        lblListitemsCountAmt.Text       = items.Count.ToString();

                        break;

                    case "Overtime Requests":
                        // Show the data
                        DataTable tableOR = new DataTable();
                        tableOR.Columns.Add("Request For");
                        tableOR.Columns.Add("Title");
                        tableOR.Columns.Add("Status");
                        tableOR.Columns.Add("Overtime Code");
                        tableOR.Columns.Add("From");
                        tableOR.Columns.Add("To");
                        tableOR.Columns.Add("Requested Hours");
                        tableOR.Columns.Add("Notes");

                        foreach (ListItem item in items)
                        {
                            try
                            {
                                if (((FieldUserValue)item["Request_x0020_For"]).LookupValue.ToString() != null)
                                {
                                    tableOR.Rows.Add(((FieldUserValue)item["Request_x0020_For"]).LookupValue, item["Title"], item["Status"],
                                                     ((FieldLookupValue)item["Overtime_x0020_Code"]).LookupValue, item["From"], item["To"],
                                                     item["Requested_x0020_Hours"], item["Notes"]);
                                }
                                else
                                {
                                    string missingNameValue = "Missing Name";
                                    tableOR.Rows.Add(missingNameValue, item["Title"], item["Status"],
                                                     ((FieldLookupValue)item["Overtime_x0020_Code"]).LookupValue, item["From"], item["To"],
                                                     item["Requested_x0020_Hours"], item["Notes"]);
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }

                        // Bind data to datagridView
                        listDataDGV.DataSource = tableOR;
                        listDataDGV.AutoResizeColumns();                                            // Resize the DataGridView columns to fit the newly loaded data.
                        listDataDGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; // Columns automatically adjust their widths when the data changes.
                        lblListitemsCountAmt.Text       = items.Count.ToString();

                        break;

                    case "CADD Office Leave Calendar":
                        // Show the data
                        DataTable tableCOLC = new DataTable();
                        tableCOLC.Columns.Add("Title");
                        tableCOLC.Columns.Add("Status");
                        tableCOLC.Columns.Add("Requested Hours");
                        tableCOLC.Columns.Add("Start Time");
                        tableCOLC.Columns.Add("End Time");

                        foreach (ListItem item in items)
                        {
                            tableCOLC.Rows.Add(item["Title"], item["Status"], item["Requested_x0020_Hours"],
                                               item["EventDate"], item["EndDate"]);
                        }

                        // Bind data to datagridView
                        listDataDGV.DataSource = tableCOLC;
                        listDataDGV.AutoResizeColumns();                                            // Resize the DataGridView columns to fit the newly loaded data.
                        listDataDGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; // Columns automatically adjust their widths when the data changes.
                        lblListitemsCountAmt.Text       = items.Count.ToString();

                        break;

                    case "TrackEmployeeTasks":
                        // Show the data
                        DataTable tableTET = new DataTable();
                        tableTET.Columns.Add("Created By");
                        tableTET.Columns.Add("Start");
                        tableTET.Columns.Add("End");
                        tableTET.Columns.Add("Title");
                        tableTET.Columns.Add("Notes");
                        tableTET.Columns.Add("TotalTaskTime");
                        tableTET.Columns.Add("Created");

                        foreach (ListItem item in items)
                        {
                            tableTET.Rows.Add(((FieldUserValue)item["Author"]).LookupValue, item["Start"], item["End"],
                                              item["Title"], item["Notes"], item["TotalTaskTime"], item["Created"]);
                        }

                        // Bind data to datagridView
                        listDataDGV.DataSource = tableTET;
                        listDataDGV.AutoResizeColumns();                                            // Resize the DataGridView columns to fit the newly loaded data.
                        listDataDGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; // Columns automatically adjust their widths when the data changes.
                        lblListitemsCountAmt.Text       = items.Count.ToString();

                        break;
                    } // END ON PREM SWITCH
                }     // END IF

                // ******************** POPULATE DATAGRIDVIEW VIA SP ONLINE ***************************
                else
                {
                    MessageBox.Show("Retrieving via SharePoint Online ...");

                    SPOnlineContext = ClaimClientContext.GetAuthenticatedContext(cboSiteURL.SelectedItem.ToString());

                    //Get the site
                    Web site = SPOnlineContext.Web;
                    SPOnlineContext.Load(site);
                    //Get Lists
                    SPOnlineContext.Load(site.Lists);
                    // Execute
                    SPOnlineContext.ExecuteQuery();


                    List      _list = SPOnlineContext.Web.Lists.GetByTitle(cboSiteList.SelectedItem.ToString());
                    CamlQuery query = new CamlQuery();
                    query.ViewXml = "<View/>";
                    ListItemCollection items = _list.GetItems(query);

                    SPOnlineContext.Load(items);
                    SPOnlineContext.ExecuteQuery();

                    string selectedList = cboSiteList.SelectedItem.ToString();

                    switch (selectedList)
                    {
                    default:
                        DataTable table = new DataTable();
                        table.Columns.Add("Title");

                        foreach (ListItem item in items)
                        {
                            table.Rows.Add(item["Title"]);
                        }

                        // Bind data to datagridView
                        listDataDGV.DataSource    = table;
                        lblListitemsCountAmt.Text = items.Count.ToString();

                        break;

                    case "All Grant Submits":
                        // Show the data
                        DataTable tableAGS = new DataTable();
                        //table.Columns.Add("Id");
                        tableAGS.Columns.Add("Name(Grant/Municipality)");
                        tableAGS.Columns.Add("Contact Name");
                        tableAGS.Columns.Add("Email");
                        tableAGS.Columns.Add("Phone");
                        tableAGS.Columns.Add("District");
                        tableAGS.Columns.Add("Comments");

                        foreach (ListItem item in items)
                        {
                            tableAGS.Rows.Add(item["Title"], item["Contact_x0020_Name"], item["Email"], item["Phone"],
                                              ((FieldLookupValue)item["District"]).LookupValue, item["Comments"]);
                        }

                        // Bind data to datagridView
                        listDataDGV.DataSource = tableAGS;
                        listDataDGV.AutoResizeColumns();                                            // Resize the DataGridView columns to fit the newly loaded data.
                        listDataDGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; // Columns automatically adjust their widths when the data changes.
                        lblListitemsCountAmt.Text       = items.Count.ToString();

                        break;

                    case "AllGrantSubmits":
                        // Show the data
                        DataTable tableAGSs = new DataTable();
                        //table.Columns.Add("Id");
                        tableAGSs.Columns.Add("Name(Grant/Municipality)");
                        tableAGSs.Columns.Add("Contact Name");
                        tableAGSs.Columns.Add("Email");
                        tableAGSs.Columns.Add("Phone");
                        tableAGSs.Columns.Add("District");
                        tableAGSs.Columns.Add("Comments");

                        foreach (ListItem item in items)
                        {
                            tableAGSs.Rows.Add(item["Title"], item["Contact_x0020_Name"], item["Email"], item["Phone"],
                                               ((FieldLookupValue)item["District"]).LookupValue, item["Comments"]);
                        }

                        // Bind data to datagridView
                        listDataDGV.DataSource = tableAGSs;
                        listDataDGV.AutoResizeColumns();                                            // Resize the DataGridView columns to fit the newly loaded data.
                        listDataDGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; // Columns automatically adjust their widths when the data changes.
                        lblListitemsCountAmt.Text       = items.Count.ToString();

                        break;

                    case "AllGrantSubmits-Archive2017":
                        // Show the data
                        DataTable tableAGSArchive17 = new DataTable();
                        //table.Columns.Add("Id");
                        tableAGSArchive17.Columns.Add("Name(Grant/Municipality)");
                        tableAGSArchive17.Columns.Add("Contact Name");
                        tableAGSArchive17.Columns.Add("Email");
                        tableAGSArchive17.Columns.Add("Phone");
                        tableAGSArchive17.Columns.Add("District");
                        tableAGSArchive17.Columns.Add("Comments");

                        foreach (ListItem item in items)
                        {
                            tableAGSArchive17.Rows.Add(item["Title"], item["Contact_x0020_Name"], item["Email"], item["Phone"],
                                                       ((FieldLookupValue)item["District"]).LookupValue, item["Comments"]);
                        }

                        // Bind data to datagridView
                        listDataDGV.DataSource = tableAGSArchive17;
                        listDataDGV.AutoResizeColumns();                                            // Resize the DataGridView columns to fit the newly loaded data.
                        listDataDGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; // Columns automatically adjust their widths when the data changes.
                        lblListitemsCountAmt.Text       = items.Count.ToString();

                        break;
                    } //END ON LINE SWITCH
                }     //END ELSE
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #6
0
        // Copy Method - w\Attahcments
        private void CopyingProcessV2()
        {
            try
            {
                if (IsSPOnline == true)
                {
                    SPOnlineContext = ClaimClientContext.GetAuthenticatedContext(cboSiteURL.SelectedItem.ToString());
                    SP.List sourceList = SPOnlineContext.Web.Lists.GetByTitle(cboSourceSiteList.SelectedItem.ToString());

                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml = @"";

                    ListItemCollection sourceCollListItem = sourceList.GetItems(camlQuery);
                    SPOnlineContext.Load(sourceCollListItem);
                    SPOnlineContext.ExecuteQuery();

                    int count = 0;

                    SP.List destinationList = SPOnlineContext.Web.Lists.GetByTitle(cboDestSiteList.SelectedItem.ToString());

                    foreach (ListItem sourceListItem in sourceCollListItem)
                    {
                        string srcList  = cboSourceSiteList.SelectedItem.ToString();
                        string destList = cboDestSiteList.SelectedItem.ToString();

                        ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                        ListItem destinationListItem = destinationList.AddItem(itemCreateInfo);

                        switch (cboDestSiteList.SelectedItem.ToString())
                        {
                        case "AllGrantSubmits-2017x":

                            destinationListItem["Title"] = sourceListItem["Title"];
                            destinationListItem["Contact_x0020_Name"] = sourceListItem["Contact_x0020_Name"];
                            destinationListItem["Email"] = sourceListItem["Email"];
                            destinationListItem["Phone"] = sourceListItem["Phone"];

                            FieldLookupValue district = ((FieldLookupValue)sourceListItem["District"]);
                            destinationListItem["District"] = district.LookupId;
                            //destinationListItem["Comments"] = sourceListItem["Comments"];

                            destinationListItem.Update();
                            SPOnlineContext.Load(destinationListItem);
                            SPOnlineContext.ExecuteQuery();

                            //ctx.ExecuteQuery();
                            UpdateAttachments(SPOnlineContext, SPOnlineContext, sourceListItem.Id, destinationListItem.Id, srcList, destList);

                            count++;

                            break;
                        } // END Switch
                    }     // END FOR

                    MessageBox.Show("Transfer Completed! " + count + " item(s) copied");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                MessageBox.Show("Error Encountered " + ex.Message);
            }
        }
예제 #7
0
        // Copy Method
        private void CopyingProcess()
        {
            try
            {
                if (IsSPOnline == true)
                {
                    SPOnlineContext = ClaimClientContext.GetAuthenticatedContext(cboSiteURL.SelectedItem.ToString());
                    SP.List sourceList = SPOnlineContext.Web.Lists.GetByTitle(cboSourceSiteList.SelectedItem.ToString());

                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml = @"";

                    ListItemCollection sourceCollListItem = sourceList.GetItems(camlQuery);
                    SPOnlineContext.Load(sourceCollListItem);
                    SPOnlineContext.ExecuteQuery();

                    int count = 0;

                    SP.List destinationList = SPOnlineContext.Web.Lists.GetByTitle(cboDestSiteList.SelectedItem.ToString());

                    foreach (ListItem sourceListItem in sourceCollListItem)
                    {
                        ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                        ListItem destinationListItem = destinationList.AddItem(itemCreateInfo);

                        switch (cboDestSiteList.SelectedItem.ToString())
                        {
                        case "AllGrantSubmits-Archive2017":

                            destinationListItem["Title"] = sourceListItem["Title"];
                            destinationListItem["Contact_x0020_Name"] = sourceListItem["Contact_x0020_Name"];
                            destinationListItem["Email"] = sourceListItem["Email"];
                            destinationListItem["Phone"] = sourceListItem["Phone"];

                            FieldLookupValue district = ((FieldLookupValue)sourceListItem["District"]);
                            destinationListItem["District"] = district.LookupId;

                            destinationListItem["Comments"] = sourceListItem["Comments"];

                            destinationListItem.Update();
                            SPOnlineContext.Load(destinationListItem);
                            SPOnlineContext.ExecuteQuery();
                            count++;

                            break;
                        } // END Switch
                    }     // END FOR

                    MessageBox.Show("Transfer Completed! " + count + " item(s) copied");
                }

                else
                {
                    // SP ON PREM Selections
                    SPOnPremContext = new ClientContext(cboSiteURL.SelectedItem.ToString());
                    SP.List sourceList = SPOnPremContext.Web.Lists.GetByTitle(cboSourceSiteList.SelectedItem.ToString());

                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml = @"";

                    ListItemCollection sourceCollListItem = sourceList.GetItems(camlQuery);
                    SPOnPremContext.Load(sourceCollListItem);
                    SPOnPremContext.ExecuteQuery();

                    int count = 0;

                    SP.List destinationList = SPOnPremContext.Web.Lists.GetByTitle(cboDestSiteList.SelectedItem.ToString());

                    foreach (ListItem sourceListItem in sourceCollListItem)
                    {
                        ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                        ListItem destinationListItem = destinationList.AddItem(itemCreateInfo);

                        switch (cboDestSiteList.SelectedItem.ToString())
                        {
                        case "CADD Office Leave Calendar":

                            FieldUserValue rf_user = ((FieldUserValue)sourceListItem["Request_x0020_For"]);
                            destinationListItem["Request_x0020_For"] = rf_user.LookupId;

                            destinationListItem["Title"] = ((FieldUserValue)sourceListItem["Request_x0020_For"]).LookupValue;
                            //destinationListItem["From"] = sourceListItem["From"];
                            //destinationListItem["To"] = sourceListItem["To"];

                            // Copies Custom [From] and [To] Form field data to built-in Form fields [Start Time] [End Time]
                            destinationListItem["EventDate"] = sourceListItem["From"];
                            destinationListItem["EndDate"]   = sourceListItem["To"];

                            destinationListItem["Requested_x0020_Hours"] = sourceListItem["Requested_x0020_Hours"];

                            destinationListItem.Update();
                            SPOnPremContext.Load(destinationListItem);
                            SPOnPremContext.ExecuteQuery();
                            count++;

                            break;
                        } // END Switch
                    }     //END FOR

                    MessageBox.Show("Transfer Completed! " + count + " item(s) copied");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                MessageBox.Show("Error Encountered " + ex.Message);
            }
        }