Exemplo n.º 1
0
        public static void UpdateView(string listName, string viewID, string viewQuery, string viewViewFields, string viewAggregations, string viewRowLimit)
        {
            using (SharePointWS_Views.Views viewsService = new SharePointWS_Views.Views())
            {
                viewsService.Credentials = System.Net.CredentialCache.DefaultCredentials;
                string viewsWebServiceUrl = string.Format("{0}/_vti_bin/Views.asmx", SiteURL);

                viewsService.Url = viewsWebServiceUrl;

                XmlNode viewXmlNode = default(XmlNode);

                XmlNode viewProperties = null;
                XmlNode formats        = null;

                try
                {
                    viewXmlNode = viewsService.UpdateView(
                        listName,
                        viewID,
                        viewProperties,
                        Util.ConvertToXmlNode(viewQuery),
                        Util.ConvertToXmlNode(viewViewFields),
                        Util.ConvertToXmlNode(viewAggregations),
                        formats,
                        Util.ConvertToXmlNode(viewRowLimit));
                }
                catch (Exception ex)
                {
                    // TODO: Handle this better.  Should not display from Util class.
                    MessageBox.Show(string.Format("Error Updating {0} Views{1}{2}", listName, "\n", ex));
                }
            }
        }
Exemplo n.º 2
0
        public static void DeleteView(string listName, string viewName)
        {
            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);


                viewsService.DeleteView(listName, viewName);
            }
        }
Exemplo n.º 3
0
        public static void LoadListViewDetailsFromSite(string listName, string viewName, Data.ApplicationDS.dtViewsRow viewRow)
        {
            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);

                // You get more if you get the individual View (by name which is the GUID)
                GetListViewDetails(listName, viewsService, viewName, viewRow);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method is private, there is a public method that can be called, LoadListViewDetailsFromSite()
        /// </summary>
        /// <param name="listName"></param>
        /// <param name="viewsService"></param>
        /// <param name="viewName"></param>
        /// <param name="viewRow"></param>
        internal static void GetListViewDetails(string listName, SharePointWS_Views.Views viewsService, string viewName, Data.ApplicationDS.dtViewsRow viewRow)
        {
            XmlNode xmlViewNode = default(XmlNode);

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            xmlViewNode = viewsService.GetView(listName, viewName);

            stopWatch.Stop();

            if (Common.DebugLevel2)
            {
                Common.WriteToDebugWindow(string.Format("GetListViewDetails(): {0} - {1}", listName, stopWatch.ElapsedMilliseconds));
            }

            viewRow.Name        = xmlViewNode.Attributes["Name"].Value;
            viewRow.Type        = xmlViewNode.Attributes["Type"].Value;
            viewRow.DisplayName = xmlViewNode.Attributes["DisplayName"].Value;
            // For some reason the URL returned by GetView() does not include the full SiteUrl.
            // We have already populated it so just skip.  TODO NB.  The previous program used this one.  Need
            // to decide which to use.
            viewRow.Url           = xmlViewNode.Attributes["Url"].Value;
            viewRow.Level         = xmlViewNode.Attributes["Level"].Value;
            viewRow.BaseViewID    = xmlViewNode.Attributes["BaseViewID"].Value;
            viewRow.ContentTypeID = xmlViewNode.Attributes["ContentTypeID"].Value;

            try
            {
                viewRow.ImageUrl = xmlViewNode.Attributes["ImageUrl"].Value;
            }
            catch (Exception)
            {
                viewRow.ImageUrl = "<none>";
            }

            // Get the OuterXml to make later use easier.

            try
            {
                viewRow.Query = Util.FormatXml(xmlViewNode["Query"].OuterXml);
            }
            catch (Exception)
            {
                viewRow.Query = "<none>";
            }

            viewRow.ViewFields = Util.FormatXml(xmlViewNode["ViewFields"].OuterXml);

            try
            {
                viewRow.RowLimit = Util.FormatXml(xmlViewNode["RowLimit"].OuterXml);
            }
            catch (Exception)
            {
                viewRow.RowLimit = "<none>";
            }

            try
            {
                viewRow.Aggregations = Util.FormatXml(xmlViewNode["Aggregations"].OuterXml);
            }
            catch (Exception)
            {
                viewRow.Aggregations = "<none>";
            }

            viewRow.OuterXml = xmlViewNode.OuterXml;

            viewRow.DetailsLoadTime   = DateTime.Now;
            viewRow.ViewDetailsLoaded = true;
        }
Exemplo n.º 5
0
        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;
            }
        }