Example #1
0
        private void LoadControls()
        {
            int index = 0;

            dtWpData.Tables.Clear();
            lstWebParts.Items.Clear();
            lstWebParts.ClearSelected();
            dgProperties.DataSource = null;
            dgProperties.ClearSelection();
            _changes.Rows.Clear();

            try
            {
                _wColl = _mySiteObj.GetWebPartsList();
            }
            catch (MySiteDoesNotExistException ex)
            {
                MessageBox.Show(ex.Message, "Error");
                return;
            }
            catch (UserNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Error");
                return;
            }

            foreach (System.Web.UI.WebControls.WebParts.WebPart wpPart in _wColl)
            {
                #region Add Webparts to ListBox and and there properties

                lstWebParts.Items.Add(new WebPartItem(wpPart.Title, wpPart.ID, wpPart.GetType().AssemblyQualifiedName));
                dtWpData.Tables.Add(new DataTable());
                dtWpData.Tables[index].Columns.Add("Property");
                dtWpData.Tables[index].Columns.Add("Type");

                dtWpData.Tables[index].Columns.Add("Value");
                dtWpData.Tables[index].Columns.Add("Assembly");
                dtWpData.Tables[index].Columns.Add("IsDirty");
                dtWpData.Tables[index].Columns.Add("PropertyType");

                Ref.PropertyInfo[] propInfoColl = wpPart.GetType().GetProperties();


                foreach (Ref.PropertyInfo propInfo in propInfoColl)
                {
                    Object[] attribColl = propInfo.GetCustomAttributes(true);

                    foreach (Object obj in attribColl)
                    {
                        #region Add Attribute to DT

                        if (obj is WebBrowsableAttribute)
                        {
                            WebBrowsableAttribute browAtt = (WebBrowsableAttribute)obj;

                            if (browAtt.Browsable)
                            {
                                Object value = propInfo.GetValue(wpPart, null);
                                dtWpData.Tables[index].Rows.Add(propInfo.Name, propInfo.PropertyType, value, propInfo.PropertyType.AssemblyQualifiedName, false, propInfo.PropertyType.ToString());


                                break;
                            }
                        }

                        else if (obj is WebPartStorageAttribute)
                        {
                            WebPartStorageAttribute storAtt = obj as WebPartStorageAttribute;
                            if (storAtt.Storage == Storage.Personal)
                            {
                                Object value = propInfo.GetValue(wpPart, null);

                                dtWpData.Tables[index].Rows.Add(propInfo.Name, propInfo.PropertyType, value, propInfo.PropertyType.AssemblyQualifiedName, false, propInfo.PropertyType.ToString());

                                break;
                            }
                        }
                        #endregion
                    }
                }

                index++;
            }

            dtOriginal = dtWpData.Copy();



            #endregion
        }