private void DisableToolbar2()
        {
            //SPList list = web.Lists[new Guid(listWebPart.ListName)];
            //SPView webpartView = list.Views[new Guid(listWebPart.ViewGuid)];

            _view.GetType().InvokeMember("EnsureFullBlownXmlDocument",
                                         BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,
                                         null,
                                         _view,
                                         null);

            PropertyInfo nodeProp = _view.GetType().GetProperty("Node",
                                                                BindingFlags.NonPublic | BindingFlags.Instance);
            XmlNode node = nodeProp.GetValue(_view, null) as XmlNode;

            if (node != null)
            {
                XmlNode toolbarNode = node.SelectSingleNode("Toolbar");
                if (toolbarNode != null)
                {
                    toolbarNode.Attributes["Type"].Value = "None";
                    _view.Update();
                }
            }
        }
        public void SetToolbarType(SPView spView, string toolBarType)
        {
            spView.GetType().InvokeMember("EnsureFullBlownXmlDocument",
             BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,
             null, spView, null, System.Globalization.CultureInfo.CurrentCulture);
            PropertyInfo nodeProp = spView.GetType().GetProperty("Node",
            BindingFlags.NonPublic | BindingFlags.Instance);
            XmlNode node = nodeProp.GetValue(spView, null) as XmlNode;

            XmlNode toolbarNode = node.SelectSingleNode("Toolbar");
            if (toolbarNode != null)
            {
                toolbarNode.Attributes["Type"].Value = toolBarType;
            }
        }
Esempio n. 3
0
        private void EnsureListViews(ref SPList list, ref SPWeb web)
        {
            if (Views != null && Views.Count > 0)
            {
                foreach (ListView iView in Views)
                {
                    SPView view = null;
                    try
                    {
                        if (iView.DefaultView)
                        {
                            view = list.DefaultView;
                        }
                        else
                        {
                            view = list.Views[iView.ViewName];
                        }
                    }
                    catch { view = null; /* as expected */ }

                    if (view == null)
                    {
                        #region Create configured View

                        view = list.Views.Add(iView.ViewName, iView.ViewFields, iView.Query, iView.RowLimit,
                                              iView.Paged, iView.MakeDefaultView, iView.ViewType, false);

                        #endregion
                    }
                    else
                    {
                        #region Reconfigure View

                        view.ViewFields.DeleteAll();
                        foreach (var iField in iView.ViewFields)
                        {
                            view.ViewFields.Add(iField);
                        }

                        view.Query    = iView.Query;
                        view.RowLimit = iView.RowLimit;
                        view.Paged    = iView.Paged;
                        view.Title    = iView.ViewName;
                        if (iView.MakeDefaultView)
                        {
                            view.DefaultView = iView.MakeDefaultView;
                        }

                        #endregion
                    }
                    if (iView.ViewStyle >= 0)
                    {
                        view.ApplyStyle(web.ViewStyles.StyleByID(iView.ViewStyle));
                    }

                    // set additional flags
                    view.Hidden      = iView.Hidden;
                    view.Scope       = iView.AllItemsWithoutFolders ? SPViewScope.Recursive : SPViewScope.Default;
                    view.TabularView = iView.TabularView;

                    object[] setToolbarParam = new object[1];
                    if (iView.ToolbarType == ToolBarType.Summary)
                    {
                        setToolbarParam[0] = "Freeform";
                    }
                    else if (iView.ToolbarType == ToolBarType.Full)
                    {
                        setToolbarParam[0] = "Standard";
                    }
                    else
                    {
                        setToolbarParam[0] = "None";
                    }
                    if (setToolbarParam[0] as string != view.ToolbarType)
                    {
                        Type[]     toolbarMethodParamTypes = { Type.GetType("System.String") };
                        MethodInfo setToolbarTypeMethod    = view.GetType().GetMethod("SetToolbarType", BindingFlags.Instance | BindingFlags.NonPublic, null, toolbarMethodParamTypes, null);
                        setToolbarTypeMethod.Invoke(view, setToolbarParam);
                    }

                    view.Update();
                }
                list.Update();
            }
        }