internal static bool DeleteFileToSPLib(string fileName, string webUrl, string libName) { try { SPAccount account = Global.SPAccounts().FirstOrDefault(s => s.SPSite.ToLower() == webUrl.ToLower()); if (account == null) { Global.WriteLog("There is no SPAccount entry for " + webUrl + " in the setting xml file.", EventLogEntryType.Error); return(false); } using (context = new ClientContext(webUrl)) { SecureString securePassword = new SecureString(); foreach (var passwordChar in account.Password) { securePassword.AppendChar(passwordChar); } context.Credentials = new SharePointOnlineCredentials(account.UserName, securePassword); context.Load(context.Web, w => w.Title); context.ExecuteQuery(); Microsoft.SharePoint.Client.ListCollection collList = context.Web.Lists; context.LoadQuery(collList.Include( list => list.Title, list => list.Id, list => list.Hidden, list => list.BaseType)); context.Load(collList); context.ExecuteQuery(); var targetList = collList.FirstOrDefault(l => l.Title.ToLower() == libName.ToLower()); var existingFile = CheckIfItemAlreadyExistByDisplayName(fileName, targetList); if (existingFile != null && existingFile.Count() != 0) { var existingItem = existingFile.FirstOrDefault(); context.Load(existingItem); context.ExecuteQuery(); existingItem.DeleteObject(); context.ExecuteQuery(); } return(true); } } catch (Exception ex) { Global.WriteLog(string.Format("Can not delete the file {0} in the SP lib {1}. Reason: ", fileName, libName, ex.Message), EventLogEntryType.Error); return(false); } }
public MainWindow() { InitializeComponent(); try { LogManage.LogInit(); //DBManage.sqlConnection = "Server=117.106.85.18;Database = YanQingYiZhongDB;Uid=sa;Pwd =sa@2016"; // DBManage.sqlConnection = "Server=192.168.1.72;Database = DaYuYiXiaoDB;Uid=sa;Pwd =sa123??;"; DBManage.sqlConnection = System.Configuration.ConfigurationManager.ConnectionStrings["contr"].ToString(); //cmb_Config(); spClient.ListCollection listCollection = client.GetAllLists(webSite, userName, password, domain); foreach (var item in listCollection) { if (item.Title == "123" || item.Title == "表单模板" || item.Title == "网站页面" || item.Title == "网站资产" || item.Title == "微源" || item.Title == "文档" || item.Title == "样式库" || item.Title == "左侧导航" || item.Title == "appdata" || item.Title == "fpdatasources" || item.Title == "TaxonomyHiddenList" || item.Title == "Web 部件库" || item.Title == "wfpub" || item.Title == "左侧导航" || item.Title == "列表模板库" || item.Title == "母版页样式库" || item.Title == "内容类型发布错误日志" || item.Title == "项目策略项列表" || item.Title == "解决方案库" || item.Title == "已转换表单" || item.Title == "组合外观" ) { continue; } TextBlock txt = new TextBlock() { Text = item.Title }; txt.MouseLeftButtonDown += txt_MouseLeftButtonDown; txt.MouseRightButtonDown += txt_MouseRightButtonDown; txt.Tag = item; listBox.Items.Add(txt); } } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } //foreach (var item in listBox.Items) //{ // Thread.Sleep(5000); // this.txt_MouseLeftButtonDown(item, null); //} //cmb_Config(); }
private void button1_Click(object sender, EventArgs e) { var tt = this.webBrowser1.Document.Body.InnerHtml; //var pp = this.webBrowser1.Document.GetElementsByTagName("s4-itm-cbx s4-itm-imgCbx"); //var pp = tt.Split(new string[] { "s4-itm-cbx s4-itm-imgCbx" }, StringSplitOptions.RemoveEmptyEntries); //var html= webBrowser1.DocumentText; List <HtmlTag> tags = HtmlTag.FindTagByAttr(tt, "div", "class", "s4-itm-cbx s4-itm-imgCbx"); List <HtmlTag> tags1 = HtmlTag.FindTagByAttr(tt, "div", "name", "Count"); spClient.ListCollection listCollection = client.GetAllLists(webSite, userName, password, domain); }
public static void LoadLists(TreeNode parentNode, SPClient.ListCollection lists, MainBrowser form) { try { SPClient.ClientContext ctx = GetClientContext(parentNode); ctx.Load(lists); ctx.ExecuteQuery(); int total = lists.Count; int current = 0; foreach (SPClient.List list in lists) { TreeNode node = parentNode.Nodes.Add(string.Format("{0} ({1})", list.Title, list.ItemCount)); node.ImageKey = SPHelp.GetFileName(list.ImageUrl); node.SelectedImageKey = SPHelp.GetFileName(list.ImageUrl); node.ContextMenuStrip = form.mnContextItem; node.Tag = list; if (list.Hidden) { node.ForeColor = Color.Gray; } AddLoadingNode(node, "Fields", Constants.IMAGE_SITE_COLUMN, LoadType.ListFields); AddLoadingNode(node, "Content Types", Constants.IMAGE_CONTENT_TYPE, LoadType.ListContentTypes); AddLoadingNode(node, "Views", Constants.IMAGE_VIEW, LoadType.ListViews); AddLoadingNode(node, "Role Assignments", Constants.IMAGE_ROLE_ASSIGNMENT, LoadType.ListRoleAssignments); AddLoadingNode(node, "Workflow Associations", Constants.IMAGE_WORKFLOW_ASSOCIATION, LoadType.ListWorkflowAssociations); // Add root folder LoadFolder(node, list.RootFolder, form, true); // Update progress current++; ItemLoaded(null, new ItemLoadedEventArgs() { TotalItem = total, CurrentItem = current }); } } catch (Exception ex) { MessageBox.Show(ex.Message, form.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); AddLoadingNode(parentNode, LoadType.WebLists); } }
protected void btnGetTasks_Click(object sender, EventArgs e) { string SiteCollectionURL = txtSiteCollection.Text; CLOM.ClientContext context = new CLOM.ClientContext(SiteCollectionURL); CLOM.Web site = context.Web; CLOM.ListCollection lists = site.Lists; var taskList = context.Web.Lists.GetByTitle("Tasks"); CLOM.CamlQuery query = new CamlQuery(); CLOM.ListItemCollection myTaskList = taskList.GetItems(query); context.Load(myTaskList); context.ExecuteQuery(); foreach (CLOM.ListItem tmpTaskItem in myTaskList) { lblTasks.Text += tmpTaskItem.FieldValues.Values.ElementAt(2).ToString() + "<br/>"; } }
private void button1_Click(object sender, EventArgs e) { string siteUrl = textBox1.Text; SP.ClientContext clientContext = new SP.ClientContext(siteUrl); SP.Web oWebsite = clientContext.Web; SP.ListCollection collList = oWebsite.Lists; clientContext.Load(collList); clientContext.ExecuteQuery(); string data = ""; foreach (SP.List oList in collList) { data = "Title: " + oList.Title + "Created: " + oList.Created.ToString(); comboBox1.Items.Add(data); } }
public void Prueba() { ClientContext clientContext = new ClientContext("http://servidors04/sitios/digitalizacion"); Web site = clientContext.Web; clientContext.Load(site); clientContext.ExecuteQuery(); //htp://servidors04/sitios/digitalizacion/_vti_history/512/seccion%20primera/Libro_2384_0001.tif Microsoft.SharePoint.Client.File file = site.GetFileByServerRelativeUrl("/sitios/digitalizacion/Seccion Primera/Libro_2384_0001.tif"); clientContext.Load(file); clientContext.ExecuteQuery(); ListItem currentItem = file.ListItemAllFields; clientContext.Load(currentItem); clientContext.ExecuteQuery(); FileVersionCollection versions = file.Versions; clientContext.Load(versions); clientContext.ExecuteQuery(); if (versions != null) { foreach (FileVersion oldFileVersion in versions) { if (oldFileVersion.VersionLabel == "1.0") { Microsoft.SharePoint.Client.ListCollection lists = site.Lists; clientContext.Load(lists); clientContext.ExecuteQuery(); } } } }
internal static bool RenameFileToSPLib(string oldFileName, string newFileName, string webUrl, string libName) { try { SPAccount account = Global.SPAccounts().FirstOrDefault(s => s.SPSite.ToLower() == webUrl.ToLower()); if (account == null) { Global.WriteLog("There is no SPAccount entry for " + webUrl + " in the setting xml file.", EventLogEntryType.Error); return(false); } using (context = new ClientContext(webUrl)) { SecureString securePassword = new SecureString(); foreach (var passwordChar in account.Password) { securePassword.AppendChar(passwordChar); } context.Credentials = new SharePointOnlineCredentials(account.UserName, securePassword); context.Load(context.Web, w => w.Title); context.ExecuteQuery(); Microsoft.SharePoint.Client.ListCollection collList = context.Web.Lists; context.LoadQuery(collList.Include( list => list.Title, list => list.Id, list => list.Hidden, list => list.BaseType)); context.Load(collList); context.ExecuteQuery(); var targetList = collList.FirstOrDefault(l => l.Title.ToLower() == libName.ToLower()); context.Load(targetList.RootFolder); context.ExecuteQuery(); var existingFile = CheckIfItemAlreadyExistByDisplayName(oldFileName, targetList); if (existingFile != null && existingFile.Count() != 0) { var file = existingFile.FirstOrDefault(); context.Load(file); context.ExecuteQuery(); string newLocation = file["FileDirRef"] + "/" + Global.CleanInvalidCharacters(Path.GetFileName(newFileName)); file.File.MoveTo(newLocation, MoveOperations.AllowBrokenThickets); context.ExecuteQuery(); } else { AddFileToSPLib(newFileName, webUrl, libName); } return(true); } } catch (Exception ex) { Global.WriteLog(string.Format("Can not rename the file {0} to the new name {1} in the SP lib {2}. Reason: {3}", Path.GetFileName(oldFileName), Path.GetFileName(newFileName), libName, ex.Message), EventLogEntryType.Error); return(false); } }
public static bool AddFileToSPLib(string fullFileName, string webUrl, string libName) { try { SPAccount account = Global.SPAccounts().FirstOrDefault(s => s.SPSite.ToLower() == webUrl.ToLower()); if (account == null) { Global.WriteLog("There is no SPAccount entry for " + webUrl + " in the setting xml file.", EventLogEntryType.Error); return(false); } SecureString securePassword = new SecureString(); foreach (var passwordChar in account.Password) { securePassword.AppendChar(passwordChar); } using (context = new ClientContext(webUrl)) { context.Credentials = new SharePointOnlineCredentials(account.UserName, securePassword); context.Load(context.Web, w => w.Title); context.ExecuteQuery(); Microsoft.SharePoint.Client.ListCollection collList = context.Web.Lists; context.LoadQuery(collList.Include( list => list.Title, list => list.Id, list => list.Hidden, list => list.BaseType)); context.Load(collList); context.ExecuteQuery(); var targetList = collList.FirstOrDefault(l => l.Title.ToLower() == libName.ToLower()); string fileName = System.IO.Path.GetFileName(fullFileName); fileName = Global.CleanInvalidCharacters(fileName); context.Load(targetList); context.ExecuteQuery(); context.Load(targetList.RootFolder); context.ExecuteQuery(); Microsoft.SharePoint.Client.File currentFile = null; var tempcurrentFile = CheckIfItemAlreadyExistByDisplayName(fileName, targetList); if (tempcurrentFile != null && tempcurrentFile.Count() != 0) { currentFile = tempcurrentFile.FirstOrDefault().File; if (targetList.ForceCheckout) { currentFile.CheckOut(); } } using (FileStream fs = new FileStream(fullFileName, FileMode.Open)) { string targetLocation = targetList.RootFolder.ServerRelativeUrl + "/" + fileName; Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, targetLocation, fs, true); } if (targetList.ForceCheckout) { currentFile.CheckIn("Updated on " + DateTime.Now, CheckinType.MajorCheckIn); } return(true); } } catch (Exception ex) { if (!ex.Message.Contains("it is being used by another process")) { Global.WriteLog(string.Format("Can not add the file {0} in the SP lib {1}. Reason: ", fullFileName, libName, ex.Message), EventLogEntryType.Error); } return(false); } }
public void getLibraryData(string strSourceURL, string strTargetURL) { try { using (spClient.ClientContext sourceContext = new spClient.ClientContext(strSourceURL)) //Site URL of InfoPath Libray { Web web = sourceContext.Web; spClient.ListCollection listColl = web.Lists; sourceContext.Load(listColl); sourceContext.ExecuteQuery(); for (int Count = 0; Count < listColl.Count; Count++) { if (listColl[Count].Title.Equals(txtLibraryName.Text.Trim())) { ASMSlibraryExist = true; break; } } if (ASMSlibraryExist) { spClient.List oList = sourceContext.Web.Lists.GetByTitle(txtLibraryName.Text.Trim()); spClient.CamlQuery camlQuery = new spClient.CamlQuery(); camlQuery.ViewXml = "<Query><OrderBy><FieldRef Name='ID' /></OrderBy></Query>"; spClient.ListItemCollection collListItem = oList.GetItems(camlQuery); sourceContext.Load(collListItem); sourceContext.ExecuteQuery(); SecureString password = new SecureString(); foreach (char c in txtPassword.Text.Trim().ToCharArray()) { password.AppendChar(c); } using (spClient.ClientContext descontext = new spClient.ClientContext(txtDesturl.Text.Trim())) { descontext.Credentials = new SharePointOnlineCredentials(txtUserName.Text.Trim(), password); spClient.Web oweb = descontext.Web; spClient.ListCollection listcoll = oweb.Lists; spClient.List spList = descontext.Web.Lists.GetByTitle(txtlistName.Text); spClient.ListItemCreationInformation itemCreateInfo = new spClient.ListItemCreationInformation(); descontext.Load(spList); descontext.ExecuteQuery(); for (int i = 0; i < collListItem.Count; i++) { try { spClient.ListItem oListItem = spList.AddItem(itemCreateInfo); sourceContext.Load(collListItem[i]); AddItemsIntoList(collListItem[i], descontext, collListItem, oListItem, spList); } catch (Exception ex) { // MessageBox.Show(ex.Message); streamWriter.WriteLine("\r\n\r\n----------------------------- Error -------------------------------"); streamWriter.WriteLine("Error Message :" + ex.Message); streamWriter.WriteLine("Stack Trace :" + ex.StackTrace); } } sourceContext.ExecuteQuery(); } } else { MessageBox.Show("Library does not exist. Please give valid InfoPath Library Name. "); } } } catch (Exception ex) { MessageBox.Show(ex.Message); streamWriter.WriteLine("\r\n\r\n----------------------------- Error -------------------------------"); streamWriter.WriteLine("Error Message :" + ex.Message); streamWriter.WriteLine("Stack Trace :" + ex.StackTrace); } }
private void btnCopy_Click(object sender, EventArgs e) { string logFileName = string.Empty, strSourceURL = string.Empty, strTargetURL = string.Empty;; try { logFileName = ConfigurationManager.AppSettings["InfoPathLog"].ToString(); if (!Directory.Exists(logFileName)) { Directory.CreateDirectory(logFileName); } if (txtLogFileName.Text.Contains(".txt")) { logFileName += txtLogFileName.Text.Trim(); } else { logFileName += txtLogFileName.Text.Trim() + ".txt"; } if (System.IO.File.Exists(logFileName)) { fsStream = new FileStream(logFileName, FileMode.Append); } else { fsStream = new FileStream(logFileName, FileMode.CreateNew); } streamWriter = new StreamWriter(fsStream); streamWriter.WriteLine("------------------------------------------------------------------------"); streamWriter.WriteLine("Date and Time Info :" + System.DateTime.Now.ToString("M/d/yyyy hh:mm:ss")); streamWriter.WriteLine("------------------------------------------------------------------------"); strSourceURL = txtSourceURL.Text.Trim(); strTargetURL = txtDesturl.Text.Trim(); streamWriter.WriteLine("Source URL :" + strSourceURL); streamWriter.WriteLine("Target URL :" + strTargetURL); SecureString password = new SecureString(); foreach (char c in txtPassword.Text.Trim().ToCharArray()) { password.AppendChar(c); } using (spClient.ClientContext SPcontext = new spClient.ClientContext(strTargetURL)) { SPcontext.Credentials = new SharePointOnlineCredentials(txtUserName.Text.Trim(), password); spClient.Web web = SPcontext.Web; SPcontext.Load(web); spClient.ListCollection listcoll = web.Lists; SPcontext.Load(listcoll); SPcontext.ExecuteQuery(); for (int count = 0; count < listcoll.Count; count++) { if (listcoll[count].Title.Equals(txtlistName.Text.Trim())) //Check whether the newly creating list is already exist { ASMSRequestsListExist = true; break; } } if (!ASMSRequestsListExist) { createListwithfields(SPcontext, txtlistName.Text.Trim()); getLibraryData(strSourceURL, strTargetURL); } else { getLibraryData(strSourceURL, strTargetURL); } } MessageBox.Show("Completed Successfully!!"); } catch (Exception ex) { MessageBox.Show(ex.Message); streamWriter.WriteLine("\r\n\r\n----------------------------- Error -------------------------------"); streamWriter.WriteLine("Error Message :" + ex.Message); streamWriter.WriteLine("Stack Trace :" + ex.StackTrace); } finally { streamWriter.Flush(); streamWriter.Close(); } }
private void btnConnect_Click(object sender, EventArgs e) { if (btnConnect.Enabled == false) { return; } progressBar1.Value = 1; progressBar1.Visible = true; string webUrl = txtUrl.Text; cmbLists.Items.Clear(); cmbLists.Enabled = false; cmbViews.Items.Clear(); cmbViews.ResetText(); cmbViews.Enabled = false; txtCaml.Clear(); txtCSharp.Clear(); txtListData.Clear(); txtViewData.Clear(); txtCaml.Enabled = false; txtCSharp.Enabled = false; txtListData.Enabled = false; txtViewData.Enabled = false; //tabControl1.Enabled = false; lblWait.Visible = true; lblViewName.Text = ""; btnCopy.Enabled = false; cmbFilterField.Enabled = false; txtFields.Clear(); txtContentTypes.Clear(); txtListID.Clear(); txtListName.Clear(); txtListTitle.Clear(); txtCreated.Clear(); txtItemCount.Clear(); txtViewID.Clear(); txtViewName.Clear(); Application.DoEvents(); try { if (chkTryFindWebUrl.Checked) { webUrl = TryToFindCorrectUrl(webUrl); } progressBar1.Value = 1; using (SP.ClientContext ctx = GetClientContext(webUrl)) { SP.Web web = ctx.Web; SP.ListCollection lists = web.Lists; ctx.Load(lists); ctx.ExecuteQuery(); progressBar1.Value++; txtUrl.Text = webUrl; foreach (var list in lists) { cmbLists.Items.Add(list.Title); } if (cmbLists.Items.Count > 0) { cmbLists.SelectedIndex = 0; } cmbLists.Enabled = true; } } catch (System.Net.WebException ex) { bool resolved = false; if (ex.Status == WebExceptionStatus.ProtocolError) { HttpWebResponse response = (HttpWebResponse)ex.Response; if (response.StatusCode == HttpStatusCode.ProxyAuthenticationRequired) { ProxyCredentialRequest frmProxy = new ProxyCredentialRequest(); frmProxy.ProxyUrl = response.ResponseUri.ToString(); if (string.IsNullOrEmpty(frmProxy.ProxyUser)) { frmProxy.ProxyUser = txtUser.Text; frmProxy.ProxyPwd = txtPwd.Text; } else { frmProxy.ProxyUser = ProxyUser; frmProxy.ProxyPwd = ProxyPwd; } DialogResult r = frmProxy.ShowDialog(); if (r == System.Windows.Forms.DialogResult.OK) { ProxyUrl = frmProxy.ProxyUrl; ProxyUser = frmProxy.ProxyUser; ProxyPwd = frmProxy.ProxyPwd; resolved = true; btnConnect_Click(null, null); } } } if (resolved == false) { ProxyUrl = ""; MessageBox.Show(ex.Message, "SgartSPQueryViewer", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "SgartSPQueryViewer", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { lblWait.Visible = false; progressBar1.Visible = false; } }
private void btnLoadForm_Click(object sender, EventArgs e) { // ===================== Populate Date Generated ============================== Word.ContentControl ccDateGenerated = GetContentControl("txtDateGenerated"); ccDateGenerated.Range.Text = DateTime.Now.ToString("MM/dd/yyyy"); String Stage = "Page Load"; WebCollection childWebs = null; String txtURL = String.Empty; Word.ContentControl ccURL = GetContentControl("txtURL"); // Clear errors SetContentControl("txtSmartArtError", ""); SetContentControl("txtURLError", ""); if (ccURL != null) { Stage = "Load Action Pane"; // http://oigportal.hhsoig.gov/sites/OAS/AATS/TMSIS txtURL = ccURL.Range.Text; txtURL = txtURL.Replace("SitePages/Home.aspx", ""); txtURL = txtURL.TrimEnd('/'); actionPane.URL = txtURL; actionPane.LoadControl(); try { Stage = "Load Web"; ClientContext clientContext = new ClientContext(txtURL); Web currentWeb = clientContext.Web; clientContext.Load(currentWeb); clientContext.ExecuteQuery(); // Get Web details Guid webId = currentWeb.Id; SetContentControl("txtTitle", currentWeb.Title); SetContentControl("txtCreated", currentWeb.Created.ToString("MM/dd/yyyy")); SetContentControl("txtModified", currentWeb.LastItemModifiedDate.ToString("MM/dd/yyyy")); long webSize = GetWebSize(currentWeb); SetContentControl("txtSize", webSize.ToString("N0")); // Set document properties Microsoft.Office.Core.DocumentProperties properties; properties = (Office.DocumentProperties) this.CustomDocumentProperties; // properties["Title"].Value = currentWeb.Title; #region Smart Art Population // ============ Smart Art ===================================================== try { // Set up for diagram Stage = "Modify Smart Art"; // for background color of the current web cell in the smartart. const int OrangeCell = unchecked ((int)0xED7D31); Site tempSite = clientContext.Site; clientContext.Load(tempSite); clientContext.ExecuteQuery(); string siteUrl = tempSite.Url + "/"; // http://oigportal.hhsoig.gov/sites/OAS Web tmpRoot = tempSite.RootWeb; clientContext.Load(tmpRoot); clientContext.ExecuteQuery(); string rootTitle = tmpRoot.Title; // Get site names by breaking down URL. // SharePoint 2010 client Web class doesn't have any way to get the parent web. // example: AATS/TMSIS string navTree = txtURL.Replace(siteUrl, ""); string[] nodes = navTree.Split('/'); // Find the diagram and get a reference to it. Word.InlineShape treeShape = null; foreach (Word.InlineShape tmpShape in this.InlineShapes) { if (tmpShape.Type == Word.WdInlineShapeType.wdInlineShapeSmartArt) { treeShape = tmpShape; } } Office.SmartArt treeArt = treeShape.SmartArt; // treeShape.Height // clear out existing nodes foreach (Office.SmartArtNode tmpNode in treeArt.Nodes) { if (tmpNode != null) { tmpNode.Delete(); } } Office.SmartArtNode rootNode = treeArt.Nodes.Add(); rootNode.TextFrame2.TextRange.Text = rootTitle; // Nodes from root to current site foreach (string tmpNodeText in nodes) { Office.SmartArtNode tmpChildNode = treeArt.Nodes.Add(); tmpChildNode.TextFrame2.TextRange.Text = tmpNodeText; } // Root node - add then node, then set the text. Office.SmartArtNode currentNode = treeArt.Nodes[treeArt.Nodes.Count]; currentNode.TextFrame2.TextRange.Text = currentWeb.Title; // set root node color currentNode.Shapes.Fill.ForeColor.RGB = 0xED7D31; // OrangeCell; // Child webs for SmartArt childWebs = currentWeb.Webs; clientContext.Load(childWebs); clientContext.ExecuteQuery(); foreach (Web tmpWeb in childWebs) { Office.SmartArtNode childNode = currentNode.AddNode(Office.MsoSmartArtNodePosition.msoSmartArtNodeBelow); childNode.TextFrame2.TextRange.Text = tmpWeb.Title; } } catch (Exception ex) { Word.ContentControl smartArtError = GetContentControl("txtSmartArtError"); Word.Range tagRange = smartArtError.Range; tagRange.Text = String.Concat("ERROR: ", ex.Message); tagRange.Font.Color = Word.WdColor.wdColorRed; } #endregion #region Build Child Web Table // ============ Child Web Table =============================================== Stage = "Load Child Web Table"; Word.Table webTable = GetTable("ChildWebs"); if (webTable != null) { foreach (Web tmpWeb in childWebs) { Word.Row newRow = webTable.Rows.Add(); newRow.Cells[1].Range.Text = tmpWeb.Title; newRow.Cells[2].Range.Text = tmpWeb.ServerRelativeUrl; // newRow.Cells[3].Range.Text = Owners newRow.Cells[4].Range.Text = tmpWeb.Created.ToString("MM/dd/yyyy"); long WebSize = GetWebSize(tmpWeb); newRow.Cells[5].Range.Text = WebSize.ToString("N0"); } } #endregion #region Build Child Object Table // ================== Child Object Table ========================================= Microsoft.SharePoint.Client.ListCollection webLists = currentWeb.Lists; clientContext.Load(webLists); clientContext.ExecuteQuery(); Word.Table objTable = GetTable("tblContentObjects"); if (objTable != null) { foreach (List tmpList in webLists) { Word.Row newRow = objTable.Rows.Add(); newRow.Cells[1].Range.Text = tmpList.BaseType.ToString(); newRow.Cells[2].Range.Text = tmpList.Title; newRow.Cells[3].Range.Text = tmpList.ItemCount.ToString(); newRow.Cells[4].Range.Text = tmpList.LastItemModifiedDate.ToString("MM/dd/yyyy"); } } #endregion #region Build Permissions Table // =================== Permissions Table ============================================== Stage = "Load Permissions Table"; Word.Table permTable = GetTable("tblPermissions"); RoleAssignmentCollection roleAssignments = currentWeb.RoleAssignments; clientContext.Load(roleAssignments); clientContext.ExecuteQuery(); Stage = "Role Assignments"; foreach (RoleAssignment assign in roleAssignments) { clientContext.Load(assign); clientContext.ExecuteQuery(); Stage = "Load Role Principal"; Principal tmpMember = assign.Member; clientContext.Load(tmpMember); clientContext.ExecuteQuery(); Word.Row newRow = permTable.Rows.Add(); newRow.Cells[1].Range.Text = assign.Member.Title; newRow.Cells[2].Range.Text = assign.Member.PrincipalType.ToString(); newRow.Cells[3].Range.Text = assign.Member.LoginName; Stage = "Role Collection"; RoleDefinitionBindingCollection roles = assign.RoleDefinitionBindings; clientContext.Load(roles); clientContext.ExecuteQuery(); Stage = "Role Definitions"; foreach (RoleDefinition roleDef in roles) { clientContext.Load(roleDef); clientContext.ExecuteQuery(); switch (roleDef.Name) { case "Full Control": newRow.Cells[4].Range.Text = "X"; break; case "Design": newRow.Cells[5].Range.Text = "X"; break; case "Contribute": newRow.Cells[6].Range.Text = "X"; break; case "Read": newRow.Cells[7].Range.Text = "X"; break; } } } #endregion #region Fill Workflow Table Stage = "Load Workflow Table"; Word.Table workflowTable = GetTable("tblWorkflows"); WorkflowAssociationCollection workflows = currentWeb.WorkflowAssociations; clientContext.Load(workflows); clientContext.ExecuteQuery(); foreach (WorkflowAssociation workflow in workflows) { clientContext.Load(workflow); clientContext.ExecuteQuery(); Word.Row newRow = workflowTable.Rows.Add(); newRow.Cells[1].Range.Text = workflow.Name; } #endregion } catch (Exception ex) { Word.ContentControl urlError = GetContentControl("txtURLError"); Word.Range rngError = urlError.Range; rngError.Text = String.Concat("ERROR at stage ", Stage, ": ", ex.Message); rngError.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorRed; } } }