private void StartBackup3(bool onlyValidate, string siteURLtoBackup, int urlCount) { SPSite sps = new SPSite(siteURLtoBackup); //note, unable to call Util.RetrieveWeb(), because it throws asynchronous errors or COM errors SPWeb web = sps.OpenWeb(); _totalSites = 0; //if (chkcompress.Checked == true) BackupRecursively(web, onlyValidate, true, true); //else // BackupRecursively(web, onlyValidate, true, false); //-- if (this.optBackupAllSubsites.Checked) { string s = (_totalSites > 1) ? "s" : ""; if (onlyValidate) { SmartStepUtil.AddToRTB(rtbDisplay, "\r\n" + _totalSites + " site" + s + " to be backed up for top site #" + urlCount + "\r\n", Color.Gray, 8, true); } else { SmartStepUtil.AddToRTB(rtbDisplay, "\r\nBatch Complete. " + _totalSites + " site" + s + " backed up for top site #" + urlCount + "\r\n", Color.Gray, 8, true); } } SmartStepUtil.ScrollToBottom(rtbDisplay); }
string _cboDocLibText; //this variable is to prevent cross-thread errors private void uploadAFolderPrep() { try { SPSite sps = new SPSite(txtTargetSite.Text); //note, unable to call Util.RetrieveWeb(), because it throws COM errors.. SPWeb web = sps.OpenWeb(); //--kickoff DirectoryInfo localSourceDirRoot = new DirectoryInfo(txtLocalSourceDir.Text); SPFolder docLibFolder = web.GetFolder(_cboDocLibText); SmartStepUtil.AddToRTB(rtbDisplay, "Upload Started\r\n", Color.Black, 12, true); if (!chkCreateRootFolderInSharepoint.Checked) { SmartStepUtil.AddToRTB(rtbDisplay, "uploading files in root folder\r\n"); } UploadAFolder(docLibFolder, localSourceDirRoot, chkCreateRootFolderInSharepoint.Checked); SmartStepUtil.AddToRTB(rtbDisplay, txtDispCounters.Text + "\r\n", Color.Brown, 8, false); SmartStepUtil.AddToRTB(rtbDisplay, "Upload Completed\r\n\r\n\r\n", Color.Green, 12, true); } catch (Eh.CancelException) { SmartStepUtil.AddToRTB(rtbDisplay, "Upload Cancelled by user\r\n", Color.Red, 12, true); } catch (Exception ex) { Eh.GlobalErrorHandler(ex); } toggleCancel(false, false, true); SmartStepUtil.ScrollToBottom(rtbDisplay); }
private void displayPermissionsInheritance(SPWeb web) { bool siteInheritsButDisplayAsPlaceholder = true; if (web.HasUniqueRoleAssignments) { AddToRtbLocal(web.ServerRelativeUrl + "\r\n", StyleType.bodyBlueBold); siteInheritsButDisplayAsPlaceholder = false; } foreach (SPList spList in web.Lists) { if (spList.HasUniqueRoleAssignments && !spList.Hidden) { if (siteInheritsButDisplayAsPlaceholder) { AddToRtbLocal(web.ServerRelativeUrl + "\r\n", StyleType.bodyDarkGray); siteInheritsButDisplayAsPlaceholder = false; } AddToRtbLocal(" " + spList.Title + "\r\n", StyleType.bodySeaGreen); } } //-- SmartStepUtil.ScrollToBottom(rtbDisplay); Application.DoEvents(); //--recursively loop through all subwebs of top level site. foreach (SPWeb subWeb in web.Webs) { displayPermissionsInheritance(subWeb); subWeb.Dispose(); } }
private void dgNewSites_DataError(object sender, DataGridViewDataErrorEventArgs e) { e.ThrowException = false; e.Cancel = true; AddToRtbLocal("Gridview DataError at row " + (e.RowIndex + 1) + ", column " + (e.ColumnIndex + 1) + " message:" + e.Exception.Message + "\r\n", StyleType.bodyRed); SmartStepUtil.ScrollToBottom(rtbDisplay); }
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); }
private void displayIt(SushiSecurable secSite) { if (!secSite.AtLeastOnePermission) { return; } AddToRtbLocal("\r\n" + secSite.Name, StyleType.bodyBlueBold); string s = chkShowLinkToManagePermissions.Checked ? secSite.HyperLinkSiteSecurity + "\r\n" : "\r\n"; SmartStepUtil.AddToRTB(rtbDisplay, " " + s, Color.DarkGray, 4, false); displayRoles(secSite, " "); foreach (SushiSecurable secList in secSite.SecurableLists) { AddToRtbLocal(" " + secList.Name, StyleType.bodySeaGreen); SmartStepUtil.AddToRTB(rtbDisplay, " (" + secList.ListType + ")", Color.SeaGreen, 8, false); string s2 = chkShowLinkToManagePermissions.Checked ? secList.HyperLinkSiteSecurity + "\r\n" : "\r\n"; SmartStepUtil.AddToRTB(rtbDisplay, " " + s2, Color.DarkGray, 5, false); displayRoles(secList, " "); } SmartStepUtil.ScrollToBottom(rtbDisplay); }
private void findRoleAssignments(SPWeb web1, SPUser user, int depth, List <string> userSharepointGroups, List <string> userADgroups) { SushiSecurable secSite = findRoleAssignmentsForMember(web1, user, userSharepointGroups, userADgroups); secSite.Name = web1.ServerRelativeUrl; secSite.HyperLinkSiteSecurity = web1.Url + "/_layouts/user.aspx"; foreach (SPList spList in web1.Lists) { SushiSecurable secList = findRoleAssignmentsForMember(spList, user, userSharepointGroups, userADgroups); if (secList.AtLeastOnePermission) { if (spList.Hidden) { continue; } secList.Name = spList.Title; secList.ListType = spList.GetType().Name; secSite.AtLeastOnePermission = true; secSite.SecurableLists.Add(secList); secList.HyperLinkSiteSecurity = spList.ParentWeb.Url + "/_layouts/user.aspx?List=" + spList.ID.ToString() + ""; } } //-- displayIt(secSite); SmartStepUtil.ScrollToBottom(rtbDisplay); Application.DoEvents(); //--recursively loop through all subwebs of top level site. foreach (SPWeb web2 in web1.Webs) { findRoleAssignments(web2, user, depth++, userSharepointGroups, userADgroups); web2.Dispose(); } }
private void validateAndUploadProfileImages2(bool onlyValidate, string pictureLibName) { try { if (onlyValidate) { AddToRtbLocal("Validating that pictures in source directory ", StyleType.bodyChocolateBold); AddToRtbLocal(txtLocalSourceDir.Text, StyleType.bodyBlueBold); AddToRtbLocal(" have a corresponding user profile\r\n", StyleType.bodyChocolateBold); } else { AddToRtbLocal("Uploading pictures from source directory ", StyleType.bodyChocolateBold); AddToRtbLocal(txtLocalSourceDir.Text, StyleType.bodyBlueBold); AddToRtbLocal(" to ", StyleType.bodyChocolateBold); AddToRtbLocal(pictureLibName, StyleType.bodyBlueBold); AddToRtbLocal(" and assigning URL to user profile\r\n", StyleType.bodyChocolateBold); } if (!Directory.Exists(txtLocalSourceDir.Text)) { Util.ShowMessageBox("Not a valid source folder: '" + txtLocalSourceDir.Text + "'"); return; } DirectoryInfo diSourceDir = new DirectoryInfo(txtLocalSourceDir.Text); using (SPSite siteCol = new SPSite(txtTargetSite.Text)) //note, unable to call Util.RetrieveWeb(), because it throws asynchronous errors or COM errors { SPWeb web = siteCol.OpenWeb(); SPServiceContext context = SPServiceContext.GetContext(web.Site); UserProfileManager profileManager = new UserProfileManager(context); SPList pictureLib = null; if (!onlyValidate) { try { pictureLib = web.Lists[pictureLibName]; } catch (Exception) { AddToRtbLocal("Unable to retrieve Picture Library\r\n", StyleType.bodyRed); return; } } string domain = txtDomainName.Text.ToUpper(); foreach (FileInfo fiImg in diSourceDir.GetFiles()) { if (_cancelNotice) { throw new Eh.CancelException(); } //--validate that picture has valid extension if (".gif.jpg.jpeg.png".IndexOf(fiImg.Extension.ToLower()) == -1) { AddToRtbLocal(fiImg.Name + " needs extention of .gif .jpg .jpeg .png ", StyleType.bodyRed, SmartStepUtil.enumIcon.red_x); AddToRtbLocal("\r\n", StyleType.bodyBlack); continue; } //--validate that user exists string UserLoginString = domain + @"\" + fiImg.Name.Remove(fiImg.Name.Length - fiImg.Extension.Length, fiImg.Extension.Length); if (profileManager.UserExists(UserLoginString)) { //--upload image to document library AddToRtbLocal(fiImg.Name + " => " + UserLoginString + " ", StyleType.bodyBlackBold, SmartStepUtil.enumIcon.green_check); if (!onlyValidate) { pictureLib.RootFolder.Files.Add(fiImg.Name, Util.getFileBytes(fiImg.FullName), true); AddToRtbLocal(" Image Uploaded", StyleType.bodySeaGreen); } AddToRtbLocal("\r\n", StyleType.bodyBlack); //--set user profile picture property if (!onlyValidate) { UserProfile u = profileManager.GetUserProfile(UserLoginString); string picUrl = web.Url.TrimEnd('/') + "/" + pictureLib.RootFolder.Name + "/" + fiImg.Name; u[PropertyConstants.PictureUrl].Value = picUrl; u.Commit(); AddToRtbLocal(" Profile picture URL set to: " + picUrl + "\r\n", StyleType.bodyDarkGray); } } else { if (GetSiteUser(web, UserLoginString) == null) // this tests whether the user is authenticated. It is possible to authenticate, but not have a Profile in the SSP. { AddToRtbLocal(fiImg.Name + " => " + UserLoginString + " not a valid site user ", StyleType.bodyOrange, SmartStepUtil.enumIcon.red_x); } else { AddToRtbLocal(fiImg.Name + " => " + UserLoginString + " valid site user, but no SSP profile ", StyleType.bodyOrange, SmartStepUtil.enumIcon.red_x); } AddToRtbLocal("\r\n", StyleType.bodyBlack); } } } AddToRtbLocal("\r\nDONE\r\n", StyleType.titleSeagreen); SmartStepUtil.ScrollToBottom(rtbDisplay); } catch (Eh.CancelException) { AddToRtbLocal("Upload Cancelled by user\r\n", StyleType.bodyRed); } catch (Exception ex) { AddToRtbLocal("error: " + ex.Message + "r\n", StyleType.bodyRed); } finally { Util.ToggleCancelLink(Util.ToggleCancelState.end, lnkCancel); _cancelNotice = false; } }
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; } }
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); } } }
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); } }
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); }
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 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); } }