Example #1
0
        private void runPermissionInheritanceForSiteCollection()
        {
            try
            {
                rtbDisplay.Clear();
                FrmCancelRunning.ToggleEnabled(true);
                using (SPWeb web = Util.RetrieveWeb(this.txtTargetSite.Text, this.rtbValidateMessage))
                {
                    AddToRtbLocal("Permissions Inheritance Report for Site ", StyleType.titleChocolate);
                    AddToRtbLocal(web.Url + "\r\n\r\n", StyleType.bodyBlueBold);

                    displayPermissionsInheritance(web);

                    SmartStepUtil.AddToRTB(rtbDisplay, "\r\nDONE", Color.Black, 8, true);
                    //AddToRtbLocal("\r\n\r\n\r\nReport Notes: This report shows all the SharePoint Sites and Lists that do not inherit permissions from their parent. Sites are displayed in blue, Lists are displayed in green. The server relative URL is used, so for example \"/\" is the root site. If a site is displayed in Gray it is simply a place holder, that site inherits permissions, but at least one of its child Lists does not. This report does not include hidden lists.", StyleType.bodyDarkGray);
                }
            }
            catch (Exception ex)
            {
                AddToRtbLocal(ex.Message, StyleType.bodyRed);
            }
            finally
            {
                FrmCancelRunning.ToggleEnabled(false);
            }
        }
Example #2
0
        private static void ShowCancelRunningForm2()
        {
            FrmCancelRunning frmCR = new FrmCancelRunning();
            frmCR.Location = new Point(MainForm.DefInstance.Left + 10, MainForm.DefInstance.Top + 10);
            DefInstance = frmCR;

            DefInstance.ShowDialog();
        }
Example #3
0
        private static void ShowCancelRunningForm2()
        {
            FrmCancelRunning frmCR = new FrmCancelRunning();

            frmCR.Location = new Point(MainForm.DefInstance.Left + 10, MainForm.DefInstance.Top + 10);
            DefInstance    = frmCR;

            DefInstance.ShowDialog();
        }
Example #4
0
        private void runFindAllPermissionsForUser()
        {
            try
            {
                rtbDisplay.Clear();
                FrmCancelRunning.ToggleEnabled(true);

                if (cboUsers.SelectedItem == null)
                {
                    AddToRtbLocal("please select a user\r\n", StyleType.bodyRed);
                    return;
                }
                using (SPWeb web = Util.RetrieveWeb(this.txtTargetSite.Text, this.rtbValidateMessage))
                {
                    //--
                    SPUser user = (SPUser)cboUsers.SelectedItem;
                    AddToRtbLocal("Permissions for user ", StyleType.titleChocolate);
                    AddToRtbLocal(user.LoginName, StyleType.titleBlue);
                    AddToRtbLocal(" site ", StyleType.bodyChocolateBold);
                    AddToRtbLocal(web.Url + "\r\n", StyleType.bodyBlueBold);

                    checkThatCurrentUserHasCorrectPriviledges(web);
                    //--build list of user's SharePoint and Active Directory Groups
                    List <string> userSharepointGroups = new List <string>();
                    foreach (SPGroup group in user.Groups)
                    {
                        userSharepointGroups.Add(group.Name.ToUpper());
                    }

                    AddToRtbLocal("Looking up Active Directory groups for user...    ", StyleType.bodyDarkGray);
                    List <string> userADgroups = findADgroupsForUser(false, user, Environment.UserDomainName);
                    AddToRtbLocal(userADgroups.Count.ToString(), StyleType.bodyBlack);
                    AddToRtbLocal(" Active Directory groups found.\r\n", StyleType.bodyDarkGray);

                    AddToRtbLocal("\r\n", StyleType.bodyBlack);
                    AddToRtbLocal("________________________________________________________________________\r\n", StyleType.bodyBlack);
                    findRoleAssignments(web, user, 1, userSharepointGroups, userADgroups);
                    AddToRtbLocal("________________________________________________________________________\r\n", StyleType.bodyBlack);

                    SmartStepUtil.AddToRTB(rtbDisplay, "\r\nDONE", Color.Black, 8, true);
                }
            }
            catch (Exception ex)
            {
                AddToRtbLocal("error: " + ex.Message, StyleType.bodyRed);
            }
            finally
            {
                FrmCancelRunning.ToggleEnabled(false);
            }
        }
Example #5
0
        public static void CloseCancelRunningFormSafely()
        {
            if (DefInstance == null)
                return;

            if (DefInstance.InvokeRequired)
            {
                DefInstance.Invoke(new delC(CloseCancelRunningFormSafely));
                return;
            }
           
            DefInstance.Close();
            DefInstance = null;
        }
Example #6
0
        public static void CloseCancelRunningFormSafely()
        {
            if (DefInstance == null)
            {
                return;
            }

            if (DefInstance.InvokeRequired)
            {
                DefInstance.Invoke(new delC(CloseCancelRunningFormSafely));
                return;
            }

            DefInstance.Close();
            DefInstance = null;
        }
Example #7
0
        private void lnkShowAllMetadata_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                FrmCancelRunning.ToggleEnabled(true); //toggleEnabled(true);
                SPList list = (SPList)cboDocLibs.SelectedItem;
                //--
                rtbDisplay.Clear();
                foreach (SPListItem listitem in list.Items)
                {
                    SmartStepUtil.AddToRTB(rtbDisplay, "Properties for  " + listitem.File.Name + "\r\n", Color.Green, 10, true);
                    List <string> props = new List <string>();
                    foreach (string item in listitem.File.Properties.Keys)
                    {
                        props.Add(item);
                    }
                    props.Sort();
                    foreach (string item in props)
                    {
                        SmartStepUtil.AddToRTB(rtbDisplay, item + ": ");
                        SmartStepUtil.AddToRTB(rtbDisplay, listitem.File.Properties[item].ToString() + "[" + listitem.File.Properties[item].GetType().Name + "]\r\n", Color.Blue, 8, false);
                    }
                    AddToRtbLocal("\r\n", StyleType.bodyBlack);

                    if (GlobalVars.CancelRunning)
                    {
                        throw new Eh.CancelException();
                    }
                }
            }
            catch (Eh.CancelException)
            {
                AddToRtbLocal("cancelled by user", StyleType.bodyBlackBold);
            }
            catch (Exception ex)
            {
                Eh.GlobalErrorHandler(ex);
            }
            finally
            {
                FrmCancelRunning.ToggleEnabled(false); //toggleEnabled(false);
            }
            SmartStepUtil.ScrollToBottom(rtbDisplay);
        }
Example #8
0
        public static void ToggleEnabled(bool running)
        {
            if (MainForm.DefInstance.InvokeRequired)
            {
                MainForm.DefInstance.Invoke(new delTE(ToggleEnabled), running);
                return;
            }

            if (running == true)
            {
                GlobalVars.CancelRunning = false;
                FrmCancelRunning.ShowCancelRunningFormOn2ndThread();
            }
            else
            {
                FrmCancelRunning.CloseCancelRunningFormSafely();
            }
            MainForm.DefInstance.Enabled = !running;
        }
Example #9
0
        private void bulkSiteCreation(bool onlyValidate)
        {
            //--Validate
            if (NewSiteOrList.ListOfNewLists == null || NewSiteOrList.ListOfNewLists.Count == 0)
            {
                AddToRtbLocal("The list of SharePoint Lists to create is empty.\r\n", StyleType.bodyRed);
                return;
            }
            if (cboListTemplates.SelectedItem == null)
            {
                AddToRtbLocal("Please select a List Template.\r\n", StyleType.bodyRed);
                return;
            }
            for (int i = 0; i < NewSiteOrList.ListOfNewLists.Count - 1; i++)
            {
                if (NewSiteOrList.ListOfNewLists[i].UrlName == NewSiteOrList.ListOfNewLists[i + 1].UrlName)
                {
                    AddToRtbLocal("The List URL " + NewSiteOrList.ListOfNewLists[i].UrlName + " is listed twice.\r\n", StyleType.bodyRed);
                    return;
                }
            }

            int counterCreated      = 0;
            int counterListToCreate = 0;

            try
            {
                FrmCancelRunning.ToggleEnabled(true);
                SPWeb parentWeb = Util.RetrieveWeb(txtTargetSite.Text, rtbSiteValidateMessage);
                if (parentWeb == null)
                {
                    return;
                }
                txtTargetSite.Text = parentWeb.Url;

                //--
                SPListTemplate targetTemplate = ((TemplateHolderForList)cboListTemplates.SelectedItem).Template;
                AddToRtbLocal("Creating new Lists beneath parent site ", StyleType.bodySeaGreen);
                AddToRtbLocal(parentWeb.Url + "\r\n", StyleType.bodyBlue);
                AddToRtbLocal("Using list template: ", StyleType.bodySeaGreen); AddToRtbLocal(targetTemplate.Name + "\r\n", StyleType.bodyBlue);
                AddToRtbLocal("\r\n", StyleType.bodyBlack);
                Application.DoEvents();

                //--
                List <NewSiteOrList> currentListUrlNamesAndTitles = new List <NewSiteOrList>();
                foreach (SPList list in parentWeb.Lists)
                {
                    currentListUrlNamesAndTitles.Add(new NewSiteOrList(list.RootFolder.Name.ToUpper(), list.Title.ToUpper()));
                }

                foreach (NewSiteOrList ns in NewSiteOrList.ListOfNewLists)
                {
                    if (GlobalVars.CancelRunning)
                    {
                        throw new Eh.CancelException();
                    }

                    counterListToCreate++;
                    AddToRtbLocal("#" + (counterListToCreate) + ") ", StyleType.bodyBlackBold);
                    if (listAlreadyExists(currentListUrlNamesAndTitles, ns))
                    {
                        AddToRtbLocal("List " + ns.UrlName + " already exists\r\n", StyleType.bodyBlue);
                    }
                    else
                    {
                        if (onlyValidate)
                        {
                            AddToRtbLocal("List to be created: ", StyleType.bodyBlack);
                            AddToRtbLocal(ns.ToString() + "\r\n", StyleType.bodyBlue);
                        }
                        else
                        {
                            AddToRtbLocal("Creating list:" + ns.ToString(), StyleType.bodyBlack);

                            Guid newListGuid = parentWeb.Lists.Add(ns.UrlName, "", targetTemplate);
                            counterCreated++;
                            SPList newList = parentWeb.Lists[newListGuid];
                            newList.Title = ns.Title;
                            newList.Update();

                            AddToRtbLocal(" success\r\n", StyleType.bodySeaGreen);

                            //--
                            if (chkAddListToQuickLanuch.Checked)
                            {
                                newList.OnQuickLaunch = true;
                                newList.Update();
                                AddToRtbLocal("  Quicklanuch node added for list\r\n", StyleType.bodyBlack);
                            }
                        }
                    }

                    SmartStepUtil.ScrollToBottom(rtbDisplay);
                    Application.DoEvents();
                }
            }
            catch (Eh.CancelException)
            {
                AddToRtbLocal("Cancelled by user\r\n", StyleType.bodyRed);
            }
            catch (Exception ex)
            {
                AddToRtbLocal("Error: " + ex.Message + "\r\n", StyleType.bodyRed);
            }
            finally
            {
                FrmCancelRunning.ToggleEnabled(false);
                AddToRtbLocal("\r\n\r\n", StyleType.bodyBlack);
                if (!onlyValidate)
                {
                    AddToRtbLocal("DONE. Count of new lists created: " + counterCreated, StyleType.bodyDarkGray);
                }
            }
        }
Example #10
0
        private void MapData(bool onlyValidate)
        {
            int counter     = 0;
            int countErrors = 0;

            try
            {
                //--validate
                if (cboMappingProfile.SelectedItem == null)
                {
                    return;
                }

                //--
                FrmCancelRunning.ToggleEnabled(true); //toggleEnabled(true);

                //--
                rtbDisplay.Clear();
                if (onlyValidate)
                {
                    AddToRtbLocal("Validating Mapping for target Document Library\r\n", StyleType.titleSeagreen);
                }
                else
                {
                    AddToRtbLocal("Mapping metadata for target Document Library\r\n", StyleType.titleSeagreen);
                }

                //--
                SPList         list = (SPList)cboDocLibs.SelectedItem;
                MappingProfile mp   = (MappingProfile)cboMappingProfile.SelectedItem;

                //--Find column ref and validate mapping profile for document library
                if (!findColoumRefFromInternalName(mp, list))
                {
                    return;
                }

                //--
                foreach (SPListItem listitem in list.Items)
                {
                    AddToRtbLocal(listitem.File.Name + "\r\n", StyleType.bodyBlackBold);
                    counter++;
                    foreach (MappingItem mi in mp.MappingItems)
                    {
                        if (onlyValidate)
                        {
                            AddToRtbLocal("   " + mi.DestColumn + " will be updated to \"" + Util.ToStr(listitem[mi.sourceID] + "\"\r\n"), StyleType.bodyBlack);
                        }
                        else
                        {
                            AddToRtbLocal("   " + mi.DestColumn + " updated to \"" + Util.ToStr(listitem[mi.sourceID] + "\"\r\n"), StyleType.bodyBlack);
                            //--for Lookup fields, need to validate format before updating
                            if (mi.DestColumn != "LookupMulti" || validateFormatOfLookup(listitem[mi.sourceID]))
                            {
                                listitem[mi.destID] = listitem[mi.sourceID];
                            }
                            //setLookupValueForPRTMproduct(listitem, mi);
                        }
                    }
                    try
                    {
                        if (!onlyValidate)
                        {
                            listitem.Update();
                        }
                    }
                    catch (Exception ex)
                    {
                        countErrors++;
                        AddToRtbLocal("Error while updating: " + ex.Message + ", continuing to next item..\r\n", StyleType.bodyRed);
                    }

                    //--
                    if (GlobalVars.CancelRunning)
                    {
                        throw new Eh.CancelException();
                    }
                    SmartStepUtil.ScrollToBottom(rtbDisplay);
                    Application.DoEvents();
                }
            }
            catch (Eh.CancelException)
            {
                SmartStepUtil.AddToRTB(rtbDisplay, "Canceled by user\r\n", Color.Black, 10, true);
            }
            catch (Exception ex)
            {
                AddToRtbLocal("error: " + ex.Message + "\r\nMessageType:" + ex.GetType().ToString() + "\r\n", StyleType.bodyRed);
            }
            finally
            {
                FrmCancelRunning.ToggleEnabled(false); //toggleEnabled(false);
            }
            string u = onlyValidate ? "validated" : "updated";

            AddToRtbLocal("\r\nNumber of documents " + u + ":" + counter + ", errors:" + countErrors + "\r\n", StyleType.bodyDarkGray);
            SmartStepUtil.ScrollToBottom(rtbDisplay);
        }
Example #11
0
        private void updateSingleColumn(bool onlyValidate)
        {
            int counterUpdated          = 0;
            int counterTotalItemsInList = 0;

            try
            {
                FrmCancelRunning.ToggleEnabled(true);//toggleEnabled(true);

                SmartStepUtil.ClearRtbSafely(rtbDisplay);
                //--validate
                if (cboCurrentValue.SelectedItem == null)
                {
                    AddToRtbLocal("Please select a Current Value", StyleType.bodyBlack);
                    return;
                }
                if (cboColumnNames.SelectedItem == null)
                {
                    AddToRtbLocal("Please select a Column", StyleType.bodyBlack);
                    return;
                }

                FieldAndContentType fnwc = (FieldAndContentType)cboColumnNames.SelectedItem;
                //--messagebox to validate if the user really wants to update value to blank. (prevent accident).
                if (txtNewValue.Text.Trim() == "" && !onlyValidate)
                {
                    if (MessageBox.Show(this, "You have selected to update to a blank, Are you sure?", "SUSHI", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        return;
                    }
                }

                //--
                string s = onlyValidate ? "Displaying" : "Updating";
                SmartStepUtil.AddToRTB(rtbDisplay, s + " values for column ", Color.Green, 14, true);
                SmartStepUtil.AddToRTB(rtbDisplay, fnwc.Field.Title, Color.Chocolate, 14, true);
                SmartStepUtil.AddToRTB(rtbDisplay, " where value = ", Color.Green, 14, true);
                SmartStepUtil.AddToRTB(rtbDisplay, "\"" + cboCurrentValue.Text + "\"\r\n", Color.Chocolate, 14, true);

                SPList list = (SPList)cboDocLibs.SelectedItem;
                counterTotalItemsInList = list.Items.Count;
                foreach (SPListItem listitem in (list.Items))
                {
                    if (GlobalVars.CancelRunning)
                    {
                        throw new Eh.CancelException();
                    }
                    SmartStepUtil.ScrollToBottom(rtbDisplay);
                    Application.DoEvents();


                    if (Util.ToStr(listitem[fnwc.Field.Id]) == cboCurrentValue.Text)
                    {
                        //object o = listitem[fnwc.Field.Id];
                        //

                        SmartStepUtil.AddToRTB(rtbDisplay, listitem.File.Name, Color.Blue, 8, false);

                        AddToRtbLocal(" column ", StyleType.bodyBlack);
                        SmartStepUtil.AddToRTB(rtbDisplay, fnwc.Field.Title, Color.DarkCyan, 8, false);

                        if (onlyValidate)
                        {
                            AddToRtbLocal(" = ", StyleType.bodyBlack);
                            SmartStepUtil.AddToRTB(rtbDisplay, "\"" + cboCurrentValue.Text + "\"\r\n", Color.DarkGreen, 8, false);
                        }
                        else
                        {
                            listitem[fnwc.Field.Id] = txtNewValue.Text;
                            listitem.Update();
                            //idea: ability to replace part of a field, rather than the whole thing.
                            //mySPLI[mySPField.Title]=mySPLI[mySPField.Title].ToString().Replace(oldValue.Text,newValue.Text);mySPLI.Update();
                            if (listitem[fnwc.Field.Id].ToString() == txtNewValue.Text)
                            {
                                AddToRtbLocal(" updated to ", StyleType.bodyBlack);
                                SmartStepUtil.AddToRTB(rtbDisplay, "\"" + txtNewValue.Text + "\"\r\n", Color.DarkBlue, 8, false);
                                counterUpdated++;
                            }
                            else
                            {
                                SmartStepUtil.AddToRTB(rtbDisplay, " NOT successfully updated\r\n", Color.Red, 8, false);
                            }
                        }
                    }
                }

                //--
                if (!onlyValidate)
                {
                    cboColumnNames_SelectedIndexChanged(null, null);
                    SmartStepUtil.AddToRTB(rtbDisplay, "update completed successfully\r\n", Color.Black, 8, true);
                }
            }
            catch (Eh.CancelException)
            {
                SmartStepUtil.AddToRTB(rtbDisplay, "Canceled by user\r\n", Color.Black, 10, true);
            }
            catch (Exception ex)
            {
                Eh.GlobalErrorHandler(ex);
            }
            finally
            {
                FrmCancelRunning.ToggleEnabled(false); //toggleEnabled(false);
            }
            SmartStepUtil.AddToRTB(rtbDisplay, "STATS: total items in list:" + counterTotalItemsInList + ", items updated:" + counterUpdated + "\r\n", Color.DarkGray, 8, false);
            SmartStepUtil.ScrollToBottom(rtbDisplay);
        }
        private void bulkSiteCreation(bool onlyValidate)
        {
            //--Validate
            if (NewSiteOrList.ListOfNewSites == null || NewSiteOrList.ListOfNewSites.Count == 0)
            {
                AddToRtbLocal("The sites to create list is empty.\r\n", StyleType.bodyRed);
                return;
            }
            if (cboSiteTemplates.SelectedItem == null)
            {
                AddToRtbLocal("Please select a Site Template.\r\n", StyleType.bodyRed);
                return;
            }
            for (int i = 0; i < NewSiteOrList.ListOfNewSites.Count - 1; i++)
            {
                if (NewSiteOrList.ListOfNewSites[i].UrlName == NewSiteOrList.ListOfNewSites[i + 1].UrlName)
                {
                    AddToRtbLocal("The Site URL " + NewSiteOrList.ListOfNewSites[i].UrlName + " is listed twice.\r\n", StyleType.bodyRed);
                    return;
                }
            }

            int counter             = 0;
            int counterListToCreate = 0;

            try
            {
                FrmCancelRunning.ToggleEnabled(true);
                SPWeb parentWeb = Util.RetrieveWeb(txtTargetSite.Text, rtbSiteValidateMessage);
                if (parentWeb == null)
                {
                    return;
                }
                txtTargetSite.Text = parentWeb.Url;

                //--
                SPWebTemplate targetTemplate = ((TemplateHolder)cboSiteTemplates.SelectedItem).Template;
                AddToRtbLocal("Creating new SubSites beneath parent site " + parentWeb.Url + "\r\n", StyleType.bodySeaGreen);
                AddToRtbLocal("Using template: ", StyleType.bodySeaGreen); AddToRtbLocal(targetTemplate.Title + "\r\n", StyleType.bodyBlue);
                AddToRtbLocal("\r\n", StyleType.bodyBlack);
                Application.DoEvents();

                //--
                List <string> currentSiteUrlNames = new List <string>();
                currentSiteUrlNames.AddRange(parentWeb.Webs.Names);
                foreach (NewSiteOrList ns in NewSiteOrList.ListOfNewSites)
                {
                    if (GlobalVars.CancelRunning)
                    {
                        throw new Eh.CancelException();
                    }

                    counterListToCreate++;
                    AddToRtbLocal("#" + counterListToCreate + ") ", StyleType.bodyBlackBold);
                    SPWeb childWeb = null;
                    if (currentSiteUrlNames.Contains(ns.UrlName))
                    {
                        AddToRtbLocal("Subsite " + ns.UrlName + " already exists\r\n", StyleType.bodyBlue);
                        childWeb = parentWeb.Webs[ns.UrlName];
                    }
                    else
                    {
                        if (onlyValidate)
                        {
                            AddToRtbLocal("Subsite to be created: ", StyleType.bodyBlack);
                            AddToRtbLocal(ns.ToString() + "\r\n", StyleType.bodyBlue);
                        }
                        else
                        {
                            AddToRtbLocal("Creating subsite:" + ns.ToString(), StyleType.bodyBlack);
                            childWeb = parentWeb.Webs.Add(ns.UrlName, ns.Title, "", 1033, targetTemplate, false, false);
                            counter++;
                            AddToRtbLocal(" success\r\n", StyleType.bodySeaGreen);

                            //--
                            AddToRtbLocal("Applying same global navigation as parent\r\n", StyleType.bodyBlack);
                            childWeb.Navigation.UseShared = true;
                        }
                    }

                    SmartStepUtil.ScrollToBottom(rtbDisplay);
                    Application.DoEvents();
                }
            }
            catch (Eh.CancelException)
            {
                AddToRtbLocal("cancelled by user\r\n", StyleType.bodyRed);
            }
            catch (Exception ex)
            {
                AddToRtbLocal("error: " + ex.Message + "\r\n", StyleType.bodyRed);
            }
            finally
            {
                FrmCancelRunning.ToggleEnabled(false);
                string s = onlyValidate ? "to be " : "";
                AddToRtbLocal("DONE. Count of sites in new sites list: " + NewSiteOrList.ListOfNewSites.Count + ", sites " + s + "created: " + counter, StyleType.bodyDarkGray);
            }
        }
Example #13
0
        private void ApplyTheme(bool onlyValidate)
        {
            rtbDisplay.Clear();
            if (cboThemes.SelectedItem == null)
            {
                AddToRtbLocal("Please select a theme.", StyleType.bodyRed);
                return;
            }
            FrmCancelRunning.ToggleEnabled(true);
            SPWeb startSite = null;

            try
            {
                startSite = Util.RetrieveWeb(txtTargetSite.Text, rtbSiteValidateMessage);

                if (startSite == null)
                {
                    return;
                }
                string which = optApplyToParentSite.Checked ? " to the selected site " : " to all children selected site ";
                AddToRtbLocal("Applying Theme ", StyleType.titleChocolate);
                AddToRtbLocal(cboThemes.SelectedItem.ToString(), StyleType.titleBlue);
                AddToRtbLocal(which, StyleType.titleChocolate);
                AddToRtbLocal(startSite.Title, StyleType.titleBlue);
                AddToRtbLocal(Util.V(onlyValidate) + "\r\n", StyleType.titleChocolate);

                //--build collection of sites to apply theme to.
                List <SPWeb> listOfSites = new List <SPWeb>();;
                if (optApplyToParentSite.Checked)
                {
                    listOfSites.Add(startSite);
                }
                else if (optApplyToChildren.Checked)
                {
                    listOfSites.Add(startSite);
                    foreach (SPWeb webChild in startSite.Webs)
                    {
                        listOfSites.Add(webChild);
                    }
                }
                else if (optApplyToAllChildrenRecursively.Checked)
                {
                    listOfSites.Add(startSite);
                    getAllChildrenRecursively(listOfSites, startSite);
                }

                //--loop through each web in list, apply theme.
                foreach (SPWeb webChild in listOfSites)
                {
                    if (GlobalVars.CancelRunning)
                    {
                        throw new Eh.CancelException();
                    }
                    Application.DoEvents();

                    AddToRtbLocal("Appling Theme to site ", StyleType.bodyBlack);
                    string url = webChild.ServerRelativeUrl + " (" + webChild.Title + ")";
                    AddToRtbLocal(url, StyleType.bodyBlue);
                    if (!onlyValidate)
                    {
                        webChild.ApplyTheme(cboThemes.SelectedItem.ToString());
                        webChild.Update();
                    }

                    if (onlyValidate)
                    {
                        AddToRtbLocal(Util.V(onlyValidate) + "\r\n", StyleType.bodyBlack);
                    }
                    else
                    {
                        AddToRtbLocal("  success\r\n", StyleType.bodySeaGreen);
                    }

                    //--
                    webChild.Dispose();
                }
                if (listOfSites.Count == 0)
                {
                    AddToRtbLocal("No sites to apply theme to.\r\n", StyleType.bodyRed);
                }
            }
            catch (Eh.CancelException)
            {
                AddToRtbLocal("cancelled by user", StyleType.bodyRed);
            }
            catch (Exception ex)
            {
                AddToRtbLocal(ex.Message, StyleType.bodyRed);
            }
            finally
            {
                FrmCancelRunning.ToggleEnabled(false);
                if (startSite != null)
                {
                    startSite.Dispose();
                }
            }
        }
        private void btnAddCt_Click(object sender, EventArgs e)
        {
            try
            {
                //TODO: add validate button
                SPContentType newCT = ((ContentTypeHolder)cboRootContentTypes.SelectedItem).CT;
                RichTextBox   rtb   = ActionMetadata.DefInstance.rtbDisplay;
                rtb.Clear();
                AddToRtbLocal("Adding Content Type to Document Library " + m_docLib.Title + "...\r\n", StyleType.titleSeagreen);

                //--
                if (!m_docLib.ContentTypesEnabled)
                {
                    m_docLib.ContentTypesEnabled = true;
                    m_docLib.Update();
                    AddToRtbLocal("Content Type management enabled for " + m_docLib.Title + "\r\n", StyleType.bodySeaGreen);
                }

                //--
                bool found = false;
                foreach (SPContentType ct in m_docLib.ContentTypes)
                {
                    if (ct.Name == newCT.Name)
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    m_docLib.ContentTypes.Add(newCT);
                    AddToRtbLocal("Content Type " + newCT.Name + " added to " + m_docLib.Title + "\r\n", StyleType.bodySeaGreen);
                }
                else
                {
                    AddToRtbLocal("Content Type " + newCT.Name + " was already previously added to " + m_docLib.Title + "\r\n", StyleType.bodyChocolate);
                }

                GlobalVars.SETTINGS.metadata_defaultContentTypeForApplyCT = newCT.Group + " - " + newCT.Name;

                //--
                if (chkChangeAllDocumentsToContentType.Checked)
                {
                    int counter = 0;
                    AddToRtbLocal("Changing all documents in library to new ContentType\r\n", StyleType.bodyBlack);
                    FrmCancelRunning.ToggleEnabled(true);  //ActionMetadata.DefInstance.toggleEnabled(true);
                    for (int i = 0; i <= m_docLib.Items.Count - 1; i++)
                    {
                        if (GlobalVars.CancelRunning)
                        {
                            throw new Eh.CancelException();
                        }

                        SPListItem      listitem             = m_docLib.Items[i];
                        SPContentTypeId currentContentTypeId = (SPContentTypeId)listitem["ContentTypeId"];

                        if (!currentContentTypeId.IsChildOf(newCT.Id))
                        {
                            listitem["ContentTypeId"] = newCT.Id;
                            listitem.Update();
                            counter++;
                            AddToRtbLocal(listitem.File.Name, StyleType.bodySeaGreen);
                            AddToRtbLocal(" ContentType-> " + newCT.Name + "\r\n", StyleType.bodyBlack);
                            SmartStepUtil.ScrollToBottom(rtb);
                            Application.DoEvents();
                        }
                    }
                    AddToRtbLocal("STATS: changed ContentType for " + counter + " documents, " + " total items in library: " + m_docLib.Items.Count + "\r\n", StyleType.bodyDarkGray);
                }

                SmartStepUtil.AddToRTB(rtb, "Done\r\n", Color.Black, 10, true);
                //--
                this.Close();
            }
            catch (Eh.CancelException)
            {
                AddToRtbLocal("canceled by user\r\n", StyleType.bodyBlackBold);
            }
            catch (Exception ex)
            {
                Eh.GlobalErrorHandler(ex);
            }
            finally
            {
                //ActionMetadata.DefInstance.toggleEnabled(false);
                FrmCancelRunning.ToggleEnabled(false);
            }
        }
Example #15
0
        private void createView(bool onlyValidate)
        {
            try
            {
                MainForm.DefInstance.Cursor = Cursors.WaitCursor;
                rtbDisplay.Clear();

                //--make sure that a favorite view has been selected and a target list
                if (cboFavoriteViews.SelectedItem == null)
                {
                    AddToRtbLocal("Please select a Favorite View\r\n", StyleType.bodyRed);
                    return;
                }
                if (cboTargetList.SelectedItem == null)
                {
                    AddToRtbLocal("Please select a Target List\r\n", StyleType.bodyRed);
                    return;
                }
                AddToRtbLocal("Copying A View" + Util.V(onlyValidate) + "\r\n", StyleType.titleSeagreen);

                //--initialize
                SPList       targetList = (SPList)cboTargetList.SelectedItem;
                FavoriteView fv         = (FavoriteView)cboFavoriteViews.SelectedItem;
                SPWeb        sourceWeb  = targetList.ParentWeb.Site.OpenWeb(fv.ParentWebURL);
                SPView       sourceView;
                try
                {
                    sourceView = sourceWeb.GetViewFromUrl(fv.ViewURL);
                }
                catch (Exception ex)
                {
                    AddToRtbLocal("Cannot find source view: \"" + fv.ViewURL + "\" " + ex.Message, StyleType.bodyRed);
                    return;
                }

                //--communicate with user
                AddToRtbLocal("View will be copied from ", StyleType.bodyChocolate); AddToRtbLocal(fv.ParentWebURL + "/" + fv.ViewURL + "\r\n", StyleType.bodyBlue);
                AddToRtbLocal("    to this SharePoint List: ", StyleType.bodyChocolate); AddToRtbLocal(targetList.RootFolder.ServerRelativeUrl, StyleType.bodyBlue);
                AddToRtbLocal(Util.V(onlyValidate) + "\r\n", StyleType.bodyChocolate);

                //--display details about view
                AddToRtbLocal("Source View Details\r\n", StyleType.bodyChocolateBold);
                string ags = Util.ToStr(sourceView.Aggregations);
                ags = (ags == "") ? "(none)" : ags;
                AddToRtbLocal("    Totals: " + ags + "\r\n", StyleType.bodyChocolate);

                string inFolders = sourceView.Scope.ToString();
                inFolders = inFolders.Replace("Default", "yes");
                inFolders = inFolders.Replace("Recursive", "no");
                AddToRtbLocal("    Show Items in Folders: " + inFolders + "\r\n", StyleType.bodyChocolate);

                AddToRtbLocal("    Item Limit: " + sourceView.RowLimit, StyleType.bodyChocolate);
                AddToRtbLocal((sourceView.Paged ? " (paging turned on)" : " (paging turned off)") + "\r\n", StyleType.bodyChocolate);

                //--check if view already exists, if it does delete it
                bool viewAlreadyExistsInTargetList = false;
                foreach (SPView view in targetList.Views)
                {
                    if (view.Title == sourceView.Title)
                    {
                        viewAlreadyExistsInTargetList = true;
                        if (!onlyValidate)
                        {
                            targetList.Views.Delete(view.ID);
                        }
                        break;
                    }
                }

                if (viewAlreadyExistsInTargetList)
                {
                    AddToRtbLocal("Note: ", StyleType.bodyChocolateBold);
                    AddToRtbLocal("View already exists in target library, deleting and recreating" + Util.V(onlyValidate) + "\r\n", StyleType.bodyChocolate);
                }

                //--verify that target library has all the fields needed in View.
                List <SourceViewField> sourceViewFields = new List <SourceViewField>();
                foreach (string viewFieldName in sourceView.ViewFields)
                {
                    sourceViewFields.Add(new SourceViewField(viewFieldName));
                }
                if (!VerifyAllViewFieldsFoundInTargetList(targetList, sourceViewFields))
                {
                    //if (!onlyValidate)
                    //{
                    //    DialogResult ret = MessageBox.Show(this, "Not all view fields exist in target list, would you like to create the view anyway?", "SUSHI - Copy a View", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                    //    if (ret == DialogResult.No)
                    //        return;
                    //}
                    AddToRtbLocal("Note: ", StyleType.bodyChocolateBold);
                    AddToRtbLocal("Not all fields exist in target List, only fields from the source view that exist in the target list will be included in the new view.\r\n", StyleType.bodyChocolate);
                }


                //--copy view into target list
                if (!onlyValidate)
                {
                    SPView newView = targetList.Views.Add(sourceView.Title, ToStringCol(sourceViewFields), sourceView.Query, sourceView.RowLimit, sourceView.Paged, true);
                    newView.Aggregations       = sourceView.Aggregations;
                    newView.AggregationsStatus = sourceView.AggregationsStatus;
                    newView.Scope = sourceView.Scope;
                    newView.Update();
                    AddToRtbLocal("View created successfully.\r\n", StyleType.titleSeagreen);
                    SmartStepUtil.ScrollToBottom(rtbDisplay);
                }
            }
            catch (Eh.CancelException)
            {
                AddToRtbLocal("cancelled by user\r\n", StyleType.bodyRed);
            }
            catch (Exception ex)
            {
                AddToRtbLocal("error: " + ex.Message + "\r\n", StyleType.bodyRed);
            }
            finally
            {
                FrmCancelRunning.ToggleEnabled(false);
                MainForm.DefInstance.Cursor = Cursors.Default;
            }
        }