private void ListPicker_FormClosed(object sender, FormClosedEventArgs e)
 {
     try
     {
         SelectedList = lstLists.SelectedItem as SPList;
         if (lvColumns.Items.Count > 0)
         {                   
             foreach (ListViewItem lvi in lvColumns.Items)
             {
                 SPColumn col = lvi.Tag as SPColumn;
                 if (col != null)
                 {
                     if (lvi.Selected)
                     {
                         if (!col.includeInCode)
                             SelectedList.AddColumnToCode(col);
                     }
                     else //don't include in code
                     {
                         if (col.includeInCode)
                             SelectedList.RemoveColumnFromCode(col);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ImportFromSharePointListTaskForm.DisplayError("Unexpected Error closing List Form", ex);
     }
 }
        public AddColumn(SPList list, ImportFromSharePointListTaskSettings settings)
        {
            if (list == null)
                throw new ArgumentNullException("list");
            if (settings == null)
                throw new ArgumentNullException("settings");

            InitializeComponent();
            _list = list;
            _settings = settings;
        }
 public static SPList Clone(SPList original)
 {
     SPList clone = new SPList();
     clone.siteUrl = original.siteUrl;
     clone.Title = original.Title;
     clone.ID = original.ID;
     clone.Description = original.Description;
     clone.Hidden = original.Hidden;
     clone.IsAppList = original.IsAppList;
     clone.IsGallery = original.IsGallery;
     foreach (SPColumn col in original._columns)
         clone._columns.Add(SPColumn.Clone(col));
     return clone;
 }
        public static List<SPColumn> GetColumnList(SPList list)
        {
            List<SPColumn> rc = new List<SPColumn>();
            using (ClientContext cc = new ClientContext(list.siteUrl))
            {
                Web site = cc.Web;
                cc.Load(site);
                cc.Load(site.Lists);
                cc.ExecuteQuery();
                List splist = site.Lists.GetById(list.ID);

                cc.Load(splist);
                cc.Load(splist.Fields);
                cc.ExecuteQuery();
                foreach (Field f in splist.Fields)
                {
                    cc.Load(f);
                    cc.ExecuteQuery();
                    try
                    {
                        switch (f.FieldTypeKind)
                        {
                            case FieldType.Integer:
                            case FieldType.Text:
                            case FieldType.Note:
                            case FieldType.DateTime:
                            case FieldType.Counter:
                            case FieldType.Choice:
                            case FieldType.Boolean:
                            case FieldType.Number:
                            case FieldType.Currency:
                            case FieldType.URL:
                            case FieldType.Guid:
                            case FieldType.MultiChoice:
                            case FieldType.GridChoice:
                            case FieldType.User:                                
                                rc.Add(new SPColumn(f, splist, -1));
                                break;
                        }
                    }
                    catch (Exception ex)
                    {                        
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                }
            }
            return rc;
        }               
        // initialize the form with the values from the settings
        protected override void OnLoad(EventArgs e)
        {
            btnLists.Enabled = false;
            _selList = Settings.SharePointList;
            if (_selList != null)
                txturl.Text = _selList.siteUrl;
            UpdateListInfo();
            UpdateColInfo();
            UpdateColButtons();

            lblServer.Text = Consumer.AssignedServer;
            lblLib.Text = Settings.outputLibrary;
            lblDS.Text = Settings.outputDataName;
            chkRemoveHTML.Checked = Settings.removeHtmlFromText;

            base.OnLoad(e);
            
        }
        public void FromXml(string xml)
        {
            XmlDocument doc = new XmlDocument();
            try
            {
                doc.LoadXml(xml);
                XmlElement el = doc["ImportFromSharePointListTask"];
                outputLibrary = el.Attributes["Library"].Value; 
                outputDataName = el.Attributes["DataSet"].Value;
                ShowHiddenLists = Convert.ToBoolean(el.Attributes["ShowHidden"].Value);
                ShowHiddenColumns = Convert.ToBoolean(el.Attributes["ShowHiddenCols"].Value);
                ShowGalleryLists = Convert.ToBoolean(el.Attributes["ShowGallery"].Value);
                if (el.HasAttribute("RemoveHTML"))
                    removeHtmlFromText = Convert.ToBoolean(el.Attributes["RemoveHTML"].Value);
                ShowApplicationLists = Convert.ToBoolean(el.Attributes["ShowApps"].Value);
                SharePointList = new SPList(el);

            }
            catch (XmlException)
            {
                // couldn't read the XML content
            }
        }
        private void btnLists_Click(object sender, EventArgs e)
        {
            ListPicker lp = new ListPicker();
            lp.SiteUrl = txturl.Text;

            SPList origList = _selList;
            SPList clone = (origList == null ? null : SPList.Clone(origList));
            lp.SelectedList = clone;
            lp.settings = this.Settings;
            if (DialogResult.OK == lp.ShowDialog(this))
            {
                _selList = lp.SelectedList;                
                UpdateListInfo();
                UpdateColInfo();
                UpdateColButtons();
            }
        }