Beispiel #1
0
        /// <summary>
        /// Delete a named view from a given list.
        /// </summary>
        /// <param name="listName">Name of the list to delete. "*" will delete the
        /// specified view from all lists. Handy when you want to delete something like
        /// Explorer view from all Document Libraries.</param>
        /// <param name="viewName">Name of the view to delete.</param>
        /// <returns></returns>
        public bool DeleteView(string listName, string viewName)
        {
            bool  rc  = false;
            Lists ws  = NewListsWebService();
            Views vws = NewViewsWebService();

            // "*" gets the collection of lists from the server then
            // proceeds to delete the view from each list
            if (listName.ToUpper() == "*")
            {
                XmlNode listCollection = ws.GetListCollection();
                foreach (XmlNode list in listCollection)
                {
                    listName = list.Attributes["Title"].Value;
                    try
                    {
                        string viewGuid = GetViewGuidByName(listName, viewName);
                        if (viewGuid != "")
                        {
                            vws.DeleteView(listName, viewGuid);
                            rc = true;
                        }
                    }
                    catch (SoapException ex)
                    {
                        Console.WriteLine(ex.Detail.InnerText);
                    }
                }
            }
            else
            {
                string viewGuid = GetViewGuidByName(listName, viewName);
                if (viewGuid != "")
                {
                    try
                    {
                        vws.DeleteView(listName, viewGuid);
                        rc = true;
                    }
                    catch (SoapException ex)
                    {
                        Console.WriteLine(ex.Detail.InnerText);
                    }
                }
            }
            return(rc);
        }