Esempio n. 1
0
        /// <summary>
        /// Load Field
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLoadField_Click(object sender, EventArgs e)
        {
            string listTitle = lbxLists.SelectedItem.ToString();

            if (string.IsNullOrEmpty(listTitle))
            {
                MessageBox.Show("Please selected list!");
            }
            else
            {
                bool hidden = this.cbxHidden.Checked;
                GetInfoFromSharePoint getInfo = new GetInfoFromSharePoint();
                string siteUrl    = this.tbxUrl.Text.Trim();
                string domain     = this.tbxDomain.Text.Trim();
                string userName   = this.tbxUserName.Text.Trim();
                string passWord   = this.tbxPassWord.Text.Trim();
                var    spContext  = new ClientContext(siteUrl);
                var    credential = new NetworkCredential(userName, passWord, domain);
                spContext.Credentials = credential;
                ArrayList fieldArr = getInfo.getListFields(spContext, hidden, listTitle);
                foreach (var item in fieldArr)
                {
                    this.cklbFields.Items.Add(item);
                }
            }
        }
Esempio n. 2
0
        public void getList()
        {
            bool   hidden  = this.cbxHidden.Checked;
            string siteUrl = this.tbxUrl.Text.Trim();

            if (string.IsNullOrEmpty(siteUrl))
            {
                MessageBox.Show("Please write siteUrl!");
            }
            else
            {
                _getInfo = new GetInfoFromSharePoint();
                //  string siteUrl = this.tbxUrl.Text.Trim();
                string domain   = this.tbxDomain.Text.Trim();
                string userName = this.tbxUserName.Text.Trim();
                string passWord = this.tbxPassWord.Text.Trim();

                try
                {
                    if (_web == null || _context == null)
                    {
                        ArrayList wc = _getInfo.getWeb(siteUrl, userName, passWord, domain);
                        _web     = (Web)wc[0];
                        _context = (ClientContext)wc[1];
                    }

                    _context.Load(_web.Lists,
                                  lists => lists.Include(list => list.Title, // For each list, retrieve Title and Id.
                                                         list => list.Id,
                                                         list => list.Hidden,
                                                         list => list.Fields));
                    // Execute query.
                    _context.ExecuteQuery();
                    foreach (var item in _web.Lists)
                    {
                        if (hidden)
                        {
                            this.lbxLists.Items.Add(item.Title);
                        }
                        else
                        {
                            if (!item.Hidden)
                            {
                                this.lbxLists.Items.Add(item.Title);
                            }
                        }
                    }
                    // MessageBox.Show("Connect success!");
                    this.lblRuning.Text = "Connect success!";
                }
                catch (Exception ee)
                {
                    // MessageBox.Show(ee.Message, "Connect Fail");
                    this.btnConnect.Enabled = true;
                    this.lblRuning.Text     = "Connect Fail!." + ee.Message;
                }
            }
            _runing.Abort();

            Thread.Sleep(5000);
            this.lblRuning.Text       = "";
            this.btnLoadLists.Enabled = true;
        }