public static void LoadListsFromSite() { // We may get called to reload the information. Clear any existing stuff. Common.ApplicationDS.dtLists.Clear(); using (SharePointWS_Lists.Lists listService = new SharePointWS_Lists.Lists()) { listService.Credentials = System.Net.CredentialCache.DefaultCredentials; listService.Url = string.Format("{0}/_vti_bin/Lists.asmx", SiteURL);; XElement listCollectionNode = null; try { listCollectionNode = listService.GetListCollection().GetXElement(); foreach (XElement node in listCollectionNode.DescendantNodes()) { Data.ApplicationDS.dtListsRow dtListRow = Common.ApplicationDS.dtLists.NewdtListsRow(); PopulateListRow(node, dtListRow); Common.ApplicationDS.dtLists.AdddtListsRow(dtListRow); } } catch (Exception ex) { MessageBox.Show(string.Format("Exception: {0}.{1}() - {2}", System.Reflection.Assembly.GetExecutingAssembly().FullName, System.Reflection.MethodInfo.GetCurrentMethod().Name, ex.ToString() )); } } }
//public static void LoadWebPartsFromPage(string pageUrl, string linkFileName) //{ // // TODO: Check to see if WebParts have already been added. If not, add them. // string searchExpression = string.Format("LinkFileName = '{0}'", linkFileName); // DataRow[] foundRows = Common.ApplicationDS.dtPages.Select(searchExpression); // // We should only ever find one row. // if (foundRows.GetLength(0) == 1) // { // if ((bool)foundRows[0]["WebPartsLoaded"] == true) // { // return; // } // } // else if (foundRows.GetLength(0) > 1 | foundRows.GetLength(0) == 0) // { // throw new ApplicationException("LoadWebPartsFromPage Fatal Error"); // } // Data.ApplicationDS.dtPagesRow pageRow = (Data.ApplicationDS.dtPagesRow)foundRows[0]; // using (SharePointWS_WebPartPages.WebPartPagesWebService webPartPageService = new SharePointWS_WebPartPages.WebPartPagesWebService()) // { // webPartPageService.Credentials = System.Net.CredentialCache.DefaultCredentials; // webPartPageService.Url = string.Format("{0}/_vti_bin/WebPartPages.asmx ", SiteURL); // XElement webPartsXml = null; // try // { // // GetWebPartProperties has been replaced with GetWebPartProperties2 // webPartsXml = webPartPageService.GetWebPartProperties2( // pageUrl, // SharePointWS_WebPartPages.Storage.Shared, // SharePointWS_WebPartPages.SPWebServiceBehavior.Version3).GetXElement(); // } // catch (Exception ex) // { // MessageBox.Show(string.Format("Exception: {0}.{1}() - {2}", // System.Reflection.Assembly.GetExecutingAssembly().FullName, // System.Reflection.MethodInfo.GetCurrentMethod().Name, // ex.ToString() // )); // } // PopulateWebPartsTable(webPartsXml, pageRow.Title, pageRow.EncodedAbsUrl); // pageRow.WebPartsLoaded = true; // } //} //private static void PopulateWebPartsTable(XElement webPartsXml, string title, string encodedAbsUrl) //{ // // CHR NOTE: All of the following work. // // 1. // // This doesn't work as the v2 stuff have a different default namespace. The v3 parts have no namespace // var webParts = webPartsXml.Elements(XName.Get("WebPart", "http://microsoft.com/sharepoint/webpartpages")); // webParts = webPartsXml.Elements(); // // 2. Note the overloaded "+" operator // XNamespace wpp = "http://microsoft.com/sharepoint/webpartpages"; // var webParts2 = webPartsXml.Elements(wpp + "WebPart"); // // 3. // XNamespace wpp2 = webPartsXml.GetDefaultNamespace(); // var webParts3 = webPartsXml.Elements(wpp2 + "WebPart"); // XName name = XName.Get("WebPart", wpp2.NamespaceName); // var webParts4 = webPartsXml.Elements(XName.Get("WebPart", webPartsXml.GetDefaultNamespace().NamespaceName)); // //Debug.Print(string.Format("LocalName <{0}> NameSpace <{1}> NameSpaceName <{2}> ToString <{3}>", // // name.LocalName, name.Namespace, name.NamespaceName, name.ToString())); // foreach (XElement node in webParts) // { // Data.ApplicationDS.dtWebPartsRow dtWebPartRow = Common.ApplicationDS.dtWebParts.NewdtWebPartsRow(); // dtWebPartRow.PageTitle = title; // dtWebPartRow.PageEncodedAbsUrl = encodedAbsUrl; // //PopulateWebPartRow(node, dtWebPartRow, nsMgr); // PopulateWebPartRow(node, dtWebPartRow); // Common.ApplicationDS.dtWebParts.AdddtWebPartsRow(dtWebPartRow); // } //} //private static void PopulateWebPartRow(XElement webPartNode, Data.ApplicationDS.dtWebPartsRow webPartRow) //{ // try // { // // All WebParts have an ID Attribute // webPartRow.ID = (string)webPartNode.Attribute("ID"); // // There seem to be two different types of WebParts. // // The v2 WebParts have all the elements directly under the <WebPart> element // if (webPartNode.GetDefaultNamespace().NamespaceName.Contains("v2")) // { // webPartRow.WebPartType = "v2"; // Data.ApplicationDS.dtWebPartV2Row v2Row = Common.ApplicationDS.dtWebPartV2.NewdtWebPartV2Row(); // PopulateWebPartRowFromV2WebPart(webPartNode, v2Row); // Common.ApplicationDS.dtWebPartV2.AdddtWebPartV2Row(v2Row); // // Go grab a few things of interest // webPartRow.Assembly = v2Row.Assembly; // webPartRow.Type = v2Row.TypeName; // } // else // { // // The v3 WebParts have a child element (in a different namespace) that contains the stuff of interest. // if ( webPartNode.Elements().First().GetDefaultNamespace().NamespaceName.Contains("v3")) // { // webPartRow.WebPartType = "v3"; // Data.ApplicationDS.dtWebPartV3Row v3Row = Common.ApplicationDS.dtWebPartV3.NewdtWebPartV3Row(); // PopulateWebPartRowFromV3WebPart(webPartNode, v3Row); // Common.ApplicationDS.dtWebPartV3.AdddtWebPartV3Row(v3Row); // // Go grab a few things of interest // char[] splitChars = new char[] { ',' }; // webPartRow.Assembly = (string)XElement.Parse(v3Row.metaData).Element(XName.Get("type", SCHEMA_V3_WEBPART)).Attribute("name").Value.Split(splitChars)[0]; // webPartRow.Type = (string)XElement.Parse(v3Row.metaData).Element(XName.Get("type", SCHEMA_V3_WEBPART)).Attribute("name").Value.Split(splitChars)[1]; // } // else // { // throw new ApplicationException("Unexpected Web Part Type"); // } // } // } // catch (Exception ex) // { // MessageBox.Show(string.Format("Exception: {0}.{1}() - {2}", // System.Reflection.Assembly.GetExecutingAssembly().FullName, // System.Reflection.MethodInfo.GetCurrentMethod().Name, // ex.ToString() // )); // } //} //private static void PopulateWebPartRowFromV2WebPart(XElement webPartNode, Data.ApplicationDS.dtWebPartV2Row webPartRow) //{ // XNamespace xmlns = webPartNode.GetDefaultNamespace(); // try // { // // Loop through the elements and populate the DataTable // // This saves having to write ugly code like this for each element // //webPartRow.Title = (string)webPartNode.Element(xmlns + "Title"); // //webPartRow.FrameState = (string)webPartNode.Element(xmlns + "FrameState"); // DataRow dataRow = (DataRow)webPartRow; // foreach(XElement item in webPartNode.Elements()) // { // //Debug.Print(string.Format(">{0}< - >{1}<", // // item.Name.LocalName, item.Value)); // //Debug.Print(string.Format("{0} - {1} - {2} - {3} - {4} - {5}", // // item.Name, // // item.Name.LocalName, // // item.Name.Namespace, // // item.Name.NamespaceName, // // item.GetType(), // // item.GetDefaultNamespace().NamespaceName)); // dataRow[item.Name.LocalName] = item.Value; // } // //DataRow dr = new DataRow(); // // Don't think we are going to need this switch logic anymore as long as // // the dtWebParts gets extended with new columns as needed. // //switch (webPartRow.TypeName) // //{ // // case "Microsoft.SharePoint.WebPartPages.ContentEditorWebPart": // // break; // // case "Microsoft.SharePoint.WebPartPages.ListViewWebPart": // // webPartRow.ListViewXml = (string)webPartNode.Element(XName.Get("ListViewXml", "http://schemas.microsoft.com/WebPart/v2/ListView")); // // break; // // default: // // break; // //} // } // catch (Exception ex) // { // MessageBox.Show(string.Format("Exception: {0}.{1}() - {2}", // System.Reflection.Assembly.GetExecutingAssembly().FullName, // System.Reflection.MethodInfo.GetCurrentMethod().Name, // ex.ToString() // )); // } //} //private static void PopulateWebPartRowFromV3WebPart(XElement webPartNode, Data.ApplicationDS.dtWebPartV3Row webPartRow) //{ // // v3 WebParts (at least the ones that have been examined so far :)) have the following structure // // <WebPart> // // <webPart> // // <metaData /> // // <data> // // <properties> // // <property /> // // ... // // </properties> // // </data> // // </webPart> // // </WebPart> // // webPartRow.ListViewXml = (string)webPartNode.Element(XName.Get("ListViewXml", SCHEMA_V3_WEBPART)); // char[] splitChars = new char[] { ',' }; // try // { // string foo1 = (string)webPartNode; // string foo2 = (string)webPartNode.Value; // string foo3 = (string)webPartNode.ToString(); // string foo4 = (string)webPartNode.Descendants().First().ToString(); // string foo5 = (string)webPartNode.Elements().First().ToString(); // string foo6 = (string)webPartNode.Descendants(XName.Get("metaData", SCHEMA_V3_WEBPART)).First().ToString(); // string foo7 = (string)webPartNode.Descendants(XName.Get("webPart", SCHEMA_V3_WEBPART)).First().ToString(); // try // { // string foo8 = (string)webPartNode.Elements(XName.Get("metaData", SCHEMA_V3_WEBPART)).First().ToString(); // } // catch(Exception ex) // { // } // try // { // string foo9 = (string)webPartNode.Elements(XName.Get("webPart", SCHEMA_V3_WEBPART)).First().ToString(); // } // catch(Exception ex) // { // } // string foo10 = (string)webPartNode.FirstNode.ToString(); // string foo11 = (string)webPartNode.Element(XName.Get("webPart", SCHEMA_V3_WEBPART)).FirstNode.ToString(); // webPartRow.metaData = (string)webPartNode.Descendants(XName.Get("metaData", SCHEMA_V3_WEBPART)).First().ToString(); // webPartRow.data = (string)webPartNode.Descendants(XName.Get("data", SCHEMA_V3_WEBPART)).First().ToString(); // //XmlNode metaDataElement = webPartNode["metaData"]; // //Common.WriteToDebugWindow(string.Format("name:{0}", metaDataElement["type"].Attributes["name"].Value)); // //// TODO: Trim the last three parts of the assembly name // //webPartRow.TypeName = metaDataElement["type"].Attributes["name"].Value.Split(splitChars)[0]; // //XmlNode dataElement = webPartNode["data"]; // //XmlNodeList propertyElements = dataElement.SelectNodes("//v3:property[@name]", nsMgr); // //Common.WriteToDebugWindow(propertyElements.Count.ToString()); // //foreach (XmlNode node in propertyElements) // //{ // // if (node.ChildNodes.Count > 0) // // { // // Common.WriteToDebugWindow(string.Format("{0} {1} {2}", node.Attributes["name"].Value, node.NodeType.ToString(), node.InnerXml.ToString())); // // } // // else // // { // // Common.WriteToDebugWindow(string.Format("{0} {1}", node.Attributes["name"].Value, node.NodeType.ToString())); // // } // //} // } // catch (Exception ex) // { // MessageBox.Show(string.Format("Exception: {0}.{1}() - {2}", // System.Reflection.Assembly.GetExecutingAssembly().FullName, // System.Reflection.MethodInfo.GetCurrentMethod().Name, // ex.ToString() // )); // } //} public static void PopulateListRow(XElement list, Data.ApplicationDS.dtListsRow listRow) { try { listRow.Title = (string)list.Attribute("Title"); listRow.ID = (string)list.Attribute("ID"); listRow.DocTemplateUrl = (string)list.Attribute("DocTemplateUrl"); listRow.DefaultViewUrl = (string)list.Attribute("DefaultViewUrl"); listRow.Description = (string)list.Attribute("Description"); listRow.ImageUrl = (string)list.Attribute("ImageUrl"); listRow.Name = (string)list.Attribute("Name"); listRow.BaseType = (string)list.Attribute("BaseType"); listRow.ServerTemplate = (string)list.Attribute("ServerTemplate"); listRow.Created = (string)list.Attribute("Created"); listRow.Modified = (string)list.Attribute("Modified"); listRow.LastDeleted = (string)list.Attribute("LastDeleted"); listRow.Version = (string)list.Attribute("Version"); listRow.Direction = (string)list.Attribute("Direction"); listRow.ThumbnailSize = (string)list.Attribute("ThumbnailSize"); listRow.WebImageHeight = (string)list.Attribute("WebImageHeight"); listRow.WebImageWidth = (string)list.Attribute("WebImageWidth"); listRow.Flags = (string)list.Attribute("Flags"); listRow.ItemCount = (string)list.Attribute("ItemCount"); listRow.AnonymousPermsMask = (string)list.Attribute("AnonymousPermMask"); listRow.RootFolder = (string)list.Attribute("RootFolder"); listRow.ReadSecurity = (string)list.Attribute("ReadSecurity"); listRow.WriteSecurity = (string)list.Attribute("WriteSecurity"); listRow.Author = (string)list.Attribute("Author"); listRow.EventSinkAssembly = (string)list.Attribute("EventSinkAssembly"); listRow.EventSinkClass = (string)list.Attribute("EventSinkClass"); listRow.EventSinkData = (string)list.Attribute("EventSinkData"); listRow.EmailInsertsFolder = (string)list.Attribute("EmailInsertsFolder"); listRow.AllowDeletion = (string)list.Attribute("AllowDeletion"); listRow.AllowMultiResponses = (string)list.Attribute("AllowMultiResponses"); listRow.EnableAttachments = (string)list.Attribute("EnableAttachments"); listRow.EnableModeration = (string)list.Attribute("EnableModeration"); listRow.EnableVersioning = (string)list.Attribute("EnableVersioning"); listRow.Hidden = (string)list.Attribute("Hidden"); listRow.MultipleDataList = (string)list.Attribute("MultipleDataList"); listRow.Ordered = (string)list.Attribute("Ordered"); listRow.ShowUser = (string)list.Attribute("ShowUser"); // Views have not been loaded for this list, yet. listRow.ViewsLoaded = false; } catch (Exception ex) { MessageBox.Show(string.Format("Exception: {0}.{1}() - {2}", System.Reflection.Assembly.GetExecutingAssembly().FullName, System.Reflection.MethodInfo.GetCurrentMethod().Name, ex.ToString() )); } }
public static void LoadListViewsFromSite(string listName, bool loadViewDetails) { // TODO: Figure out why this doesn't work. // var query = from list in Common.ApplicationDS.dtLists.AsEnumerable() // where list.Name == listName // select new // { // list // }; // MessageBox.Show(query.Count().ToString()); // Data.ApplicationDS.dtListsRow listRow = null; // foreach(var row in query) // { // //listRow = row; // row.ToString(); // } string searchExpression = string.Format("Title = '{0}'", listName); DataRow[] foundRows = Common.ApplicationDS.dtLists.Select(searchExpression); // We should only ever find one row. if (foundRows.GetLength(0) > 1) { throw new ApplicationException("LoadListViewsFromSite Fatal Error"); } Data.ApplicationDS.dtListsRow listRow = (Data.ApplicationDS.dtListsRow)foundRows[0]; if (listRow.ViewsLoaded == true) { if (!loadViewDetails) { return; } else { // TODO SOON: Walk the views for this list and see if the details have been loaded. // Load them if not. ; } } else { using (SharePointWS_Views.Views viewsService = new SharePointWS_Views.Views()) { viewsService.Credentials = System.Net.CredentialCache.DefaultCredentials; viewsService.Url = string.Format("{0}/_vti_bin/Views.asmx", SiteURL); System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); // Get the collection of views for the specified list XElement viewCollectionNode = viewsService.GetViewCollection(listName).GetXElement(); stopWatch.Stop(); if (Common.DebugLevel2) { Common.WriteToDebugWindow(string.Format("LoadListViewsFromSite(): {0} - {1}", listName, stopWatch.ElapsedMilliseconds)); } int count = 0; foreach (XElement view in viewCollectionNode.DescendantNodes()) { Data.ApplicationDS.dtViewsRow viewRow = Common.ApplicationDS.Views.NewdtViewsRow(); viewRow.ListName = listName; // You only get this information from GetViewCollection() viewRow.DisplayName = (string)view.Attribute("DisplayName"); viewRow.Name = (string)view.Attribute("Name"); viewRow.Url = (string)view.Attribute("Url"); // TODO: Find the last modification time if exist and track. Hum, unfortunately this does not exist Common.ApplicationDS.Views.AdddtViewsRow(viewRow); if (loadViewDetails) { string viewName = viewRow.Name; stopWatch.Reset(); stopWatch.Start(); // You get more if you get the individual View by name (which is the GUID) GetListViewDetails(listName, viewsService, viewName, viewRow); stopWatch.Stop(); if (Common.DebugLevel2) { Common.WriteToDebugWindow(string.Format("List GetView(Loop): {0} - {1} - {2}", listName, count, stopWatch.ElapsedMilliseconds)); } } count += 1; } } // Indicate that the views for this list have been added. listRow.ViewsLoaded = true; } }