Exemple #1
0
        /// <summary>
        /// An item is being updated.
        /// </summary>
        public override void ItemUpdating(SPItemEventProperties properties)
        {
            base.ItemUpdating(properties);

            if (properties.ListTitle == SOURCE_LIST)
            {
                try
                {
                    SPListItem theItem = properties.ListItem;

                    if (theItem.Title != properties.AfterProperties["Title"].ToString())
                    {
                        SPWeb            theSite  = properties.OpenWeb();
                        SPList           theList  = theSite.Lists[CALENDAR_LIST];
                        SPViewCollection theViews = theList.Views;

                        try { this.DeleteTheView(theViews, theItem.Title); } catch { }

                        this.CreateTheView(theViews, properties.AfterProperties["Title"].ToString());
                    }
                }
                catch (Exception ex)
                {
                    properties.ErrorMessage = ex.Message;
                    properties.Status       = SPEventReceiverStatus.CancelWithError;
                }
            }
        }
Exemple #2
0
        private void CreateNewsListView(SPWeb web, SPList list)
        {
            // create new view with custom webpart
            SPViewCollection allviews = list.Views;
            string           viewName = Constants.NEWS_LISTPAGE;

            System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();

            var view = allviews.Add(viewName, viewFields, string.Empty, 1, true, true);

            WebPartHelper.HideXsltListViewWebParts(web, view.Url);
            WebPartHelper.ProvisionWebpart(web, new WebpartPageDefinitionCollection()
            {
                new WebpartPageDefinition()
                {
                    PageUrl  = view.Url,
                    Title    = list.Title,
                    Webparts = new System.Collections.Generic.List <WebpartDefinition>()
                    {
                        new DefaultWP()
                        {
                            Index       = 0,
                            ZoneId      = "Main",
                            WebpartName = "NewsListView.webpart"
                        }
                    }
                }
            });
            WebPartHelper.MoveWebPart(web, view.Url, "NewsListView.webpart", "Main", 0);

            view.Update();
            //list.Update();
        }
        public static void DeleteViewIfExistsByDisplayName(this SPViewCollection views, string displayName)
        {
            var view = views.TryGetViewByDisplayName(displayName);

            if (view != null)
            {
                var list = view.ParentList;
                list.Views.Delete(view.ID);
                list.Update();
            }
        }
Exemple #4
0
        void SAVEbutton1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                SPViewCollection viewCollection = currentList.Views;
                if (viewCollection.Count.ToString() == ViewState["CheckViewsCount"].ToString())
                {
                    int i = 0;
                    foreach (SPView currentView in viewCollection)
                    {
                        if (currentView.Title != "")
                        {
                            Control peopleEditorControl = MainPanel.FindControl("pe" + i.ToString());
                            if (peopleEditorControl != null)
                            {
                                PeopleEditor pe = (PeopleEditor)peopleEditorControl;

                                //if (pe.IsValid == false && pe.Entities.Count != 0)
                                //    return;

                                SaveToProperties(currentView, pe.CommaSeparatedAccounts, pe.Entities.Count);
                            }

                            i++;
                        }
                    }


                    if (this.chbxPermission.Checked)
                    {
                        SaveViceVersaToProperties(currentList, false);
                    }
                    else
                    {
                        SaveViceVersaToProperties(currentList, true);
                    }

                    Close();
                }
                else
                {
                    ViewState["CheckViewsCount"] = viewCollection.Count.ToString();
                    ClientScript.RegisterStartupScript(this.GetType(), "StatusScript",
                                                       @"<script type='text/javascript'>ExecuteOrDelayUntilScriptLoaded(Initialize, 'sp.js');
                                                        function Initialize() {
                                                            statusId = SP.UI.Status.addStatus('Please Save this Page Again. Incorrect number of Views!','', true); 
                                                            SP.UI.Status.setStatusPriColor(statusId, 'red');
                                                            }</script>");
                }
            }
        }
        // a view doesn't have an internal name, only a Guid that uniquely identifies it. Hence lookup by display name
        public static SPView TryGetViewByDisplayName(this SPViewCollection views, string displayName)
        {
            SPView view = null;

            try
            {
                view = views[displayName];
            }
            catch (ArgumentException)
            {
                // intentionally left black
            }
            return(view);
        }
        private void SetTargetListView(string webId, string selectedListId)
        {
            listTargetListView.Items.Clear(); // clear list, first and foremost
            if (!string.IsNullOrEmpty(webId) && !string.IsNullOrEmpty(selectedListId))
            {
                //using (SPSite _site = SPControl.GetContextSite(this.Context)) {
                //  using (SPWeb _web = _site.OpenWeb(new Guid(webId))) {
                SPSite _site = SPControl.GetContextSite(this.Context);
                using (SPWeb _web = _site.OpenWeb(new Guid(webId)))
                {
                    SPList           list  = _web.Lists[new Guid(selectedListId)];
                    SPViewCollection views = list.Views;
                    List <ListItem>  str   = new List <ListItem>();
                    foreach (SPView v in views)
                    {
                        // use only views that are both visible and shared
                        if (!v.Hidden && !v.PersonalView)
                        {
                            str.Add(new ListItem(
                                        string.Format(CultureInfo.InvariantCulture, "{0}", v.Title), v.ID.ToString()));
                        }
                    }
                    if (str.Count > 0)
                    {
                        str.Sort(delegate(ListItem item1, ListItem item2)
                        {
                            return(item1.Text.CompareTo(item2.Text));
                        });

                        listTargetListView.Items.AddRange(str.ToArray());

                        ListItem bitem = null;
                        if (!string.IsNullOrEmpty(TargetListViewId))
                        {
                            bitem = listTargetListView.Items.FindByValue(TargetListViewId);
                        }
                        if (bitem != null)
                        {
                            listTargetListView.SelectedIndex = listTargetListView.Items.IndexOf(bitem);
                        }
                        else
                        {
                            listTargetListView.SelectedIndex = 0;
                        }
                    }
                }
            }
        }
Exemple #7
0
        private void CreateView(string viewName, string listTitle, string[] viewFields, SPWeb web)
        {
            SPList list = web.Lists.TryGetList(listTitle);

            if (list != null)
            {
                StringCollection viewFieldNames = new StringCollection();
                foreach (var viewField in viewFields)
                {
                    viewFieldNames.Add(viewField);
                }
                SPViewCollection views = list.Views;
                views.Add(viewName, viewFieldNames, null, 100, true, true);
                list.Update();
                web.Update();
            }
        }
 /// <summary>
 /// Ensures the calendar overlays.
 /// Note: This clears the existing overlays.
 /// </summary>
 /// <param name="viewCollection">The view collection.</param>
 /// <param name="overlayInfos">The overlay information objects.</param>
 /// <param name="overlayList">The overlay list.</param>
 public void EnsureCalendarOverlays(SPViewCollection viewCollection, CalendarOverlayInfo[] overlayInfos, SPList overlayList)
 {
     for (var i = 0; i < overlayInfos.Length; i++)
     {
         var overlayInfo = overlayInfos[i];
         AddCalendarOverlay(
             overlayList,
             overlayInfo.TargetViewName,
             overlayInfo.OverlayViewName,
             null,
             null,
             overlayList,
             overlayInfo.Name,
             overlayInfo.Description,
             overlayInfo.Color,
             overlayInfo.AlwaysShow,
             i == 0);
     }
 }
Exemple #9
0
        private void CreateTheView(SPViewCollection theViews, string viewName)
        {
            try
            {//if the view exist do nothing
                SPView theView = theViews[viewName];
            }
            catch
            {//if not, create it
                System.Collections.Specialized.StringCollection viewFields =
                    new System.Collections.Specialized.StringCollection();

                viewFields.Add("EventDate");
                viewFields.Add("EndDate");
                viewFields.Add("Title");
                //viewFields.Add("_x00c1_rea_x0020_reserva");
                viewFields.Add("fRecurrence");

                string query = string.Format(
                    "<Where>" +
                    "<And>" +
                    "<DateRangesOverlap>" +
                    "<FieldRef Name='EventDate' />" +
                    "<FieldRef Name='EndDate' />" +
                    "<FieldRef Name='RecurrenceID' />" +
                    "<Value Type='DateTime'><Month /></Value>" +
                    "</DateRangesOverlap>" +
                    "<Eq><FieldRef Name='Sala_x0020_reserva' /><Value Type='Text'>{0}</Value></Eq>" +
                    "</And>" +
                    "</Where>", viewName);

                SPView theView = theViews.Add(viewName, viewFields, query, 0, false, false, SPViewCollection.SPViewType.Calendar | SPViewCollection.SPViewType.Recurrence, false);
                theView.ViewData =
                    "<FieldRef Name='Title' Type='CalendarMonthTitle' />" +
                    "<FieldRef Name='Title' Type='CalendarWeekTitle' />" +
                    "<FieldRef Name='_x00c1_rea_x0020_reserva' Type='CalendarWeekLocation' />" +
                    "<FieldRef Name='Title' Type='CalendarDayTitle' />" +
                    "<FieldRef Name='_x00c1_rea_x0020_reserva' Type='CalendarDayLocation' />";
                theView.Scope      = SPViewScope.Recursive;
                theView.MobileView = true;
                theView.Update();
            }
        }
Exemple #10
0
        public static void CreateList(SPWeb web)
        {
            //SPSite site = SPContext.Current.Site;
            //site.AllowUnsafeUpdates = true;
            //SPWeb web = site.RootWeb;
            web.AllowUnsafeUpdates = true;

            SPListCollection         coll      = web.Lists;
            SPListTemplateCollection temlcoll  = web.ListTemplates;
            SPDocTemplateCollection  docTemp   = web.DocTemplates;
            SPFieldCollection        fieldcoll = web.Fields;

            SPListTemplate temp = temlcoll[0];

            //SPListTemplateType.CustomGrid is a list template that works like table in ASP.NET or Excel sheet.
            Guid gd = coll.Add(Constants.listName, "A custom list to store Record data", SPListTemplateType.CustomGrid);

            coll[gd].Fields.Add(Constants.fieldUrl, SPFieldType.Note, true);
            coll[gd].Fields.Add(Constants.fieldDate, SPFieldType.Text, true);
            coll[gd].Fields.Add(Constants.fieldUser, SPFieldType.Text, true);

            //update the custom list with all those newly created fields
            coll[gd].Update();

            //create the view for display in the site - both sides must match

            string           defaultquery = coll[gd].Views[0].Query;
            SPViewCollection viewcoll     = coll[gd].Views;
            Guid             anothergd    = coll[gd].Views[0].ID;

            viewcoll.Delete(anothergd);

            System.Collections.Specialized.StringCollection viewfields = new System.Collections.Specialized.StringCollection();

            //Title field is always needed by SharePoint sites and it is always automatically created by WSS/MOSS even though you didn't tell it to
            viewfields.Add(Constants.fieldUrl);
            viewfields.Add(Constants.fieldDate);
            viewfields.Add(Constants.fieldUser);

            coll[gd].Views.Add("View name", viewfields, defaultquery, 100, true, true);
            coll[gd].Update();
        }
Exemple #11
0
        /// <summary>
        /// An item is being deleted.
        /// </summary>
        public override void ItemDeleting(SPItemEventProperties properties)
        {
            base.ItemDeleting(properties);

            if (properties.ListTitle == SOURCE_LIST)
            {
                try
                {
                    SPListItem       theItem  = properties.ListItem;
                    SPWeb            theSite  = properties.OpenWeb();
                    SPList           theList  = theSite.Lists[CALENDAR_LIST];
                    SPViewCollection theViews = theList.Views;

                    this.DeleteTheView(theViews, theItem.Title);
                }
                catch (Exception ex)
                {
                    properties.ErrorMessage = ex.Message;
                    properties.Status       = SPEventReceiverStatus.Continue;
                }
            }
        }
        public static void CreateDefaultListView(SPList list)
        {
            SPViewCollection views    = list.Views;
            string           viewName = Language.SMUListViewName;

            System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
            viewFields.Add("ID");
            viewFields.Add("Type");
            viewFields.Add("smReceivers");
            viewFields.Add("Author");
            viewFields.Add("Created");


            StringBuilder query = new StringBuilder();

            query.Append("<Where></Where><OrderBy><FieldRef Name='Created' Ascending='FALSE' /></OrderBy>");
            views.Add(viewName, viewFields, query.ToString(), 100, true, true);
            SPView allItems = views.Cast <SPView>().FirstOrDefault(p => p.Title == "All Items");

            if (allItems != null)
            {
                views.Delete(allItems.ID);
            }
        }
        public void BuildPersonalViewMenu(SPView view, Page page, SPList spList = null)
        {
            try
            {
                if (view == null && spList == null)
                {
                    return;
                }

                HtmlGenericControl personalViewDiv = UtilityControl.FindControl <HtmlGenericControl>(page, "divForPersonalView", false).FirstOrDefault();
                if (personalViewDiv == null)
                {
                    return;
                }

                HtmlGenericControl control = new HtmlGenericControl(HtmlTextWriterTag.Div.ToString());
                control.Attributes.Add(HtmlTextWriterAttribute.Class.ToString(), "nav-leftNavigationContainer");

                ASPxTreeView treeControl = new ASPxTreeView
                {
                    EnableViewState  = false,
                    TextField        = ListViewDelegateControls.NavigationElementDisplayNameAttr,
                    NodeLinkMode     = ItemLinkMode.TextOnly,
                    NavigateUrlField = ListViewDelegateControls.NavigationElementLinkAttr,
                    ID = "treePersonalView"
                };

                treeControl.Images.CollapseButton.Url = "/_layouts/15/images/Navicon/LeftNavigation/minus.png";
                treeControl.Images.ExpandButton.Url   = "/_layouts/15/images/Navicon/LeftNavigation/plus.png";

                PersonalViewsStructs personalViewsStructs = new PersonalViewsStructs();
                PersonalViewsStructs childrensStructs     = new PersonalViewsStructs();
                PersonalViewsStruct  rootPersonalView     = new PersonalViewsStruct
                {
                    DisplayName = PersonalViewHeadText,
                    Id          = Guid.NewGuid().ToString().Replace("-", "_"),
                    Link        = "javascript:void(0)",
                    Children    = childrensStructs
                };
                personalViewsStructs.Add(rootPersonalView);

                SPViewCollection spViewCollection = spList != null ? spList.Views : view.ParentList.Views;

                childrensStructs.AddRange(from SPView spView in spViewCollection
                                          where spView.PersonalView
                                          select new PersonalViewsStruct
                {
                    DisplayName = spView.Title,
                    Link        = string.Format(ViewHrefFormat, spView.ParentList.ID, spView.ID),
                    Id          = spList != null ? spList.ID.ToString().Replace("-", "_") : view.ID.ToString().Replace("-", "_")
                });

                if (personalViewsStructs.Count == 1 && personalViewsStructs[0].HasChildren)
                {
                    control.Controls.Add(treeControl);
                    personalViewDiv.Controls.Add(control);
                    personalViewDiv.Visible = true;
                    treeControl.DataSource  = personalViewsStructs;
                    treeControl.DataBind();
                    treeControl.ExpandAll();
                }
            }
            catch (Exception ex)
            {
                Logger.ShowErrorOnPage("Не удалось изменить/сохранить отображение ", ex);
            }
        }
        private void PopulateAndSync()
        {
            SPSite          site = SPContext.Current.Site;
            SPWeb           web  = site.RootWeb;
            SPWebCollection webs = site.AllWebs;
            SPList          list = null;
            //SPListCollection lists = null;
            List <SPList>    lists = new List <SPList>();
            SPView           view  = null;
            SPViewCollection views = null;
            //SPFieldCollection fields = null;
            SPViewFieldCollection viewfields = null;

            if (!string.IsNullOrEmpty(source.Title))
            {
                tbx_name.Text = source.Title;
            }
            #region Webs

            ddl_webs.DataSource     = webs;
            ddl_webs.DataTextField  = "Title";
            ddl_webs.DataValueField = "ID";

            if (!string.IsNullOrEmpty(source.WebId))
            {
                try
                {
                    Guid WebId = new Guid(source.WebId);
                    web = site.OpenWeb(WebId);
                    ddl_webs.SelectedValue = web.ID.ToString();
                }
                catch (Exception)
                {
                    web = site.RootWeb;
                }
            }

            //lists = web.Lists;

            foreach (SPList _list in web.Lists)
            {
                if (!_list.Hidden)
                {
                    if (_list.BaseType == SPBaseType.DocumentLibrary)
                    {
                        if (!((SPDocumentLibrary)_list).IsCatalog)
                        {
                            lists.Add(_list);
                        }
                    }
                    else
                    {
                        lists.Add(_list);
                    }
                }
            }

            ddl_webs.DataBind();

            #endregion

            #region Lists

            ddl_lists.DataSource     = lists;
            ddl_lists.DataTextField  = "Title";
            ddl_lists.DataValueField = "ID";

            if (!string.IsNullOrEmpty(source.ListId))
            {
                try
                {
                    Guid ListId = new Guid(source.ListId);
                    list  = web.Lists.GetList(ListId, true);
                    views = list.Views;
                    ddl_lists.SelectedValue = list.ID.ToString();
                }
                catch (Exception)
                {
                    list = lists[0];
                    ddl_lists.SelectedValue = list.ID.ToString();
                    views = lists[0].Views;
                }
            }

            if (list == null)
            {
                list = lists[0];
            }
            if (views == null)
            {
                views = list.Views;
            }
            ddl_lists.DataBind();
            ddl_lists.SelectedValue = list.ID.ToString();

            #endregion

            #region Views

            ddl_views.DataSource     = views;
            ddl_views.DataTextField  = "Title";
            ddl_views.DataValueField = "ID";

            if (!string.IsNullOrEmpty(source.ViewId) && list != null)
            {
                try
                {
                    Guid ViewId = new Guid(source.ViewId);
                    view       = list.Views[ViewId];
                    viewfields = view.ViewFields;
                    ddl_views.SelectedValue = view.ID.ToString();
                }
                catch (Exception)
                {
                    view = list.Views[0];
                }
            }

            if (view == null)
            {
                view = list.Views[0];
            }

            if (viewfields == null)
            {
                viewfields = view.ViewFields;
            }

            ddl_views.DataBind();
            ddl_views.SelectedValue = view.ID.ToString();

            #endregion

            #region Fields

            cbl_fields.DataSource = viewfields;

            if (!string.IsNullOrEmpty(source.ViewFields) && view != null)
            {
                string[] _fields = source.ViewFields.Split(new char[1] {
                    ';'
                });
            }

            cbl_fields.DataBind();

            #endregion

            #region CAML

            if (!string.IsNullOrEmpty(source.Query) && view != null)
            {
                tbx_caml.Text = view.Query;
            }
            else
            {
                if (view != null)
                {
                    tbx_caml.Text = view.Query;
                }
            }

            #endregion
        }
Exemple #15
0
 private void DeleteTheView(SPViewCollection theViews, string viewName)
 {
     theViews.Delete(theViews[viewName].ID);
 }
Exemple #16
0
 internal abstract SPView Provision(SPViewCollection viewCollection, bool preserveViewFieldsCollection);
Exemple #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SAVEbutton1.Click   += new EventHandler(SAVEbutton1_Click);
            CancelButton1.Click += new EventHandler(CancelButton1_Click);

            if (Request.QueryString["List"] != null)
            {
                listGuid    = new Guid(Request.QueryString["List"]);
                currentList = spWeb.Lists[listGuid];

                if (CheckCustomRights(currentList))
                {
                    Control tagTitleControl = Page.Header.FindControl("PlaceHolderPageTitle").Parent;
                    if (tagTitleControl != null)
                    {
                        AddTagTitle(tagTitleControl);
                    }

                    Control titleLinkControl = FindInnerControl(Page, "PlaceHolderPageTitleInTitleArea");
                    if (titleLinkControl != null)
                    {
                        AddLinkTitle(titleLinkControl);
                    }

                    PageDescriptionText.Text = "View Permission (Powered by SPGuys)";

                    GenerateInnerHtml();

                    if (!Page.IsPostBack)
                    {
                        SPViewCollection viewCollection = currentList.Views;
                        ViewState["CheckViewsCount"] = viewCollection.Count.ToString();

                        int i = 0;
                        foreach (SPView currentView in viewCollection)
                        {
                            if (currentView.Title != "")
                            {
                                Control peopleEditorControl = MainPanel.FindControl("pe" + i.ToString());
                                if (peopleEditorControl != null)
                                {
                                    PeopleEditor pe = (PeopleEditor)peopleEditorControl;
                                    pe.CommaSeparatedAccounts = SelectFromProperties(currentView);
                                }

                                i++;
                            }
                        }

                        if (SelectViceVersaFromProperties(currentSite, currentList, true))
                        {
                            this.chbxPermission.Checked = true;
                        }
                        else
                        {
                            this.chbxPermission.Checked = false;
                        }
                    }
                }
                else
                {
                    SPUtility.HandleAccessDenied(new UnauthorizedAccessException());
                }
            }
            else
            {
                SPUtility.HandleAccessDenied(new UnauthorizedAccessException());
            }
        }
 /// <summary>
 /// SPBug, "name" and "Name" are different (sic!)
 /// </summary>
 /// <param name="views"></param>
 /// <param name="viewName"></param>
 /// <returns></returns>
 public static SPView FindByName(this SPViewCollection views, string viewName)
 {
     return(views
            .OfType <SPView>()
            .FirstOrDefault(v => String.Compare(v.Title, viewName, StringComparison.OrdinalIgnoreCase) == 0));
 }
        /// <summary>
        /// Ensures the view.
        /// </summary>
        /// <param name="viewCollection">The view collection.</param>
        /// <param name="viewInfo">The view information.</param>
        /// <returns>The ensured view.</returns>
        public SPView EnsureView(SPViewCollection viewCollection, ViewInfo viewInfo)
        {
            var views = viewCollection.Cast<SPView>();
            var ensuredView = views.SingleOrDefault(view => view.Title.Equals(viewInfo.Name, StringComparison.OrdinalIgnoreCase));

            // If view collection doesn't already contain a view with the same name, create it
            if (ensuredView == null)
            {
                // Create view fields string collection
                var viewFields = new StringCollection();
                viewFields.AddRange(viewInfo.ViewFields);

                if (!string.IsNullOrEmpty(viewInfo.ProjectedFields) || !string.IsNullOrEmpty(viewInfo.Joins))
                {
                    ensuredView = viewCollection.Add(
                        viewInfo.Name,
                        viewFields,
                        viewInfo.Query,
                        viewInfo.Joins,
                        viewInfo.ProjectedFields,
                        viewInfo.RowLimit,
                        viewInfo.IsPaged,
                        viewInfo.IsDefaultView,
                        viewInfo.ViewType,
                        viewInfo.IsPersonalView);
                }
                else
                {
                    ensuredView = viewCollection.Add(
                        viewInfo.Name,
                        viewFields,
                        viewInfo.Query,
                        viewInfo.RowLimit,
                        viewInfo.IsPaged,
                        viewInfo.IsDefaultView,
                        viewInfo.ViewType,
                        viewInfo.IsPersonalView);
                }

                viewCollection.List.Update();
                this.logger.Info(
                    "View '{0}' has been successfully created in list '{1}'.",
                    viewInfo.Name,
                    viewCollection.List.Title);
            }
            else
            {
                this.logger.Warn(
                    "View '{0}' has already been created in list '{1}'.  Updating the view.",
                    viewInfo.Name,
                    viewCollection.List.Title);

                // Update the existing view
                ensuredView.ViewFields.DeleteAll();
                viewInfo.ViewFields.ToList().ForEach(vf => ensuredView.ViewFields.Add(vf));
                ensuredView.Query = viewInfo.Query;
                ensuredView.Joins = viewInfo.Joins;
                ensuredView.ProjectedFields = viewInfo.ProjectedFields;
                ensuredView.RowLimit = viewInfo.RowLimit;
                ensuredView.Paged = viewInfo.IsPaged;
                ensuredView.DefaultView = viewInfo.IsDefaultView;
            }

            if (!string.IsNullOrEmpty(viewInfo.ViewData))
            {
                ensuredView.ViewData = viewInfo.ViewData;
            }

            ensuredView.Update();

            return ensuredView;
        }
Exemple #20
0
        public List <ProductCatalogData> GetListsOld()
        {
            SPDataSource ds = new SPDataSource();

            ds.DataSourceMode  = SPDataSourceMode.List;
            ds.UseInternalName = true;
            ds.Scope           = SPViewScope.Recursive;
            ds.IncludeHidden   = true;

            string queryString;

            //queryString = "<View><ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef Name='PermMask'/></ViewFields><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>5</Value></Eq></Where></Query></View>";
            //queryString = "<View><ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef Name='PermMask'/></View>";
            queryString = "<View></View>";

            ds.SelectCommand = queryString;

            Parameter dbParam_ListId = new Parameter("ListID");

            dbParam_ListId.DefaultValue = "DF806E7E-0073-4202-99E3-C4A269E2FA5D";
            ds.SelectParameters.Add(dbParam_ListId);


            SPDataSourceView          dsw;
            List <ProductCatalogData> dt = new List <ProductCatalogData>();

            dsw = ds.GetView();

            SPList xlist = dsw.List;

            SPViewCollection colViews = xlist.Views;

            foreach (SPView vView in colViews)
            {
            }

            /*
             * SPListItem newFolder = xlist.Items.Add(xlist.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, null);
             * if (newFolder != null)
             * {
             *  newFolder["Title"] = "Min Nye Folder";
             *  newFolder.Update();
             * }
             */
            System.Web.UI.DataSourceSelectArguments args = new System.Web.UI.DataSourceSelectArguments();

            SPDataSourceViewResultItem[] arrResult = (SPDataSourceViewResultItem[])dsw.Select(args);
            foreach (SPDataSourceViewResultItem Result in arrResult)
            {
                SPListItem oListItem = (SPListItem)Result.ResultItem;
                //SPField myField = xitem.Fields[new Guid("{FE7E79DD-DD68-438e-A960-E3686025D44B}")];

                ProductCatalogData r = new ProductCatalogData();
                foreach (SPField ofield in oListItem.Fields)
                {
                    string tekst;
                    try
                    {
                        tekst = ">" + ofield.Title + "< >" + ofield.InternalName + "<>" + oListItem[ofield.Id] + "<";
                    }
                    catch
                    {
                        //OK
                    }

                    switch (ofield.InternalName)
                    {
                    case "ID":
                        r.ID = (int)oListItem[ofield.Id];
                        break;

                    case "Title":
                        r.Title = (string)oListItem[ofield.Id];
                        break;
                    }
                }
                dt.Add(r);
            }

            return(dt);
        }
Exemple #21
0
        private void GenerateInnerHtml()
        {
            StringBuilder innerHtml0 = new StringBuilder();

            innerHtml0.Remove(0, innerHtml0.Length);

            SPViewCollection viewCollection = currentList.Views;

            innerHtml0.AppendLine("<table width='99%' class='ms-v4propertysheetspacing' border='0' cellSpacing='0' cellPadding='0'>");
            innerHtml0.AppendLine("<tbody>");
            innerHtml0.AppendLine(@"");


            LiteralControl nullSection = new LiteralControl(innerHtml0.ToString());

            MainPanel.Controls.Add(nullSection);

            int i = 0;

            foreach (SPView currentView in viewCollection)
            {
                if (currentView.Title != "")
                {
                    StringBuilder innerHtml = new StringBuilder();
                    innerHtml.Remove(0, innerHtml.Length);
                    innerHtml.AppendLine("<td class='ms-sectionline' height='1' colSpan='2'><img alt='' src='/_layouts/images/blank.gif' width='1' height='1'></td>");
                    innerHtml.AppendLine(@"
                    <tr>
                    <td class='ms-descriptiontext' vAlign='top'>
                        <table border='0' cellpadding='1' cellspacing='0' width='100%'>
                            <tr>
                                <td class='ms-sectionheader' style='padding-top: 4px;' height='22' valign='top'>
                                    <h3 class='ms-standardheader ms-inputformheader'>
                                        " + currentView.Title + @"
                                    </h3>
                                </td>
                            </tr>
                            <tr>
                                <td class='ms-descriptiontext ms-inputformdescription'>
                                        You can enter User names, Group names, Active Directory group names or e-mail addresses <b>which will not have the permission for this View</b>.
                                        <br />Separate them with semicolons.
                                        <br />
                                </td>
                                <td>
                                    <img src='/_layouts/images/blank.gif' width='8' height='1' alt='' />
                                </td>
                            </tr>
                        </table>
                    </td>");


                    innerHtml.AppendLine(@"<td class='ms-authoringcontrols ms-inputformcontrols' valign='top' align='left' width='40%'>");
                    innerHtml.AppendLine(@"
                <table border='0' width='100%' cellspacing='0' cellpadding='0'>
                    <tr>
                        <td width='9px'>
                            <img src='/_layouts/images/blank.gif' width='9' height='7' alt='' />
                        </td>
                        <td>
                            <img src='/_layouts/images/blank.gif' width='150' height='7' alt='' />
                        </td>
                        <td width='10px'>
                            <img src='/_layouts/images/blank.gif' width='10' height='1' alt='' />
                        </td>
                    </tr>
                    <tr>
                        <td />
                        <td class='ms-authoringcontrols'>
                            <table class='ms-authoringcontrols' border='0' width='100%' cellspacing='0' cellpadding='0'>
                                <tr>
                                    <td class='ms-authoringcontrols' colspan='2'>
                                        <span>Users/Groups:</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <img src='/_layouts/images/blank.gif' width='1' height='3' style='display: block'
                                            alt='' />
                                    </td>
                                </tr>
                                <tr>
                                    <td align='left' class='' valign='top'>");

                    LiteralControl firstSection = new LiteralControl(innerHtml.ToString());
                    MainPanel.Controls.Add(firstSection);

                    PeopleEditor peopleEditor = new PeopleEditor();
                    peopleEditor.ID = "pe" + i.ToString();

                    peopleEditor.SelectionSet     = "User,DL,SecGroup,SPGroup";
                    peopleEditor.AllowEmpty       = true;
                    peopleEditor.Rows             = 3;
                    peopleEditor.ValidatorEnabled = true;
                    peopleEditor.MultiSelect      = true;

                    MainPanel.Controls.Add(peopleEditor);

                    StringBuilder innerHtml2 = new StringBuilder();
                    innerHtml2.Remove(0, innerHtml2.Length);
                    innerHtml2.AppendLine(@"
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                        </td>
                       </tr>");
                    LiteralControl secondSection = new LiteralControl(innerHtml2.ToString());
                    MainPanel.Controls.Add(secondSection);

                    i++;
                }
            }

            StringBuilder innerHtml3 = new StringBuilder();

            innerHtml3.Remove(0, innerHtml3.Length);
            innerHtml3.AppendLine("</tbody>");
            innerHtml3.AppendLine("</table>");

            LiteralControl thirdSection = new LiteralControl(innerHtml3.ToString());

            MainPanel.Controls.Add(thirdSection);
        }