Esempio n. 1
0
        /// <summary>
        /// Sets the inital values of controls
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected override void OnLoad(EventArgs e)
        {
            if (this.Page.Request["__EVENTTARGET"] == RibbonPostbackId)
            {
                _event = this.Page.Request["__EVENTARGUMENT"];
            }

            if (_event == "Add")
            {
                Response.Redirect("/_layouts/Hemrika/ManageWebSiteModule.aspx?Source=/_layouts/Hemrika/ManageWebSiteModules.aspx", true);
            }

            // If AccessControl rules have not been created, they will need to be and therefore, AllowUnsafeUpdates must be set to true
            SPControl.GetContextWeb(Context).AllowUnsafeUpdates = true;

            foreach (IWebSiteControllerModule module in WebSiteControllerConfig.Modules)
            {
                TableRow  row  = new TableRow();
                TableCell cell = new TableCell();
                cell.CssClass = "ms-descriptionText";
                HyperLink link = new HyperLink();
                link.NavigateUrl = "~/_layouts/Hemrika/ManageWebSiteModule.aspx?guid=" + module.Id.ToString() + "&Source=/_layouts/Hemrika/ManageWebSiteModules.aspx";
                link.Text        = module.GetType().FullName;
                cell.Controls.Add(link);
                row.Cells.Add(cell);
                this.entriesTable.Rows.Add(row);
            }

            SPControl.GetContextWeb(Context).AllowUnsafeUpdates = false;
        }
Esempio n. 2
0
        private void LoadResourceFileStrings()
        {
            try
            {
                string        resources             = GetResourceDirectory();
                DirectoryInfo directoryInfo         = new DirectoryInfo(this.Page.Server.MapPath(resources));
                FileInfo[]    languageFileInfoArray = directoryInfo.GetFiles(STR_LANGUAGE_FILTER);

                SPWeb web;
                for (int n = 0; n < languageFileInfoArray.Length; n++)
                {
                    FileInfo fileInfo = languageFileInfoArray[n];
                    web = SPControl.GetContextWeb(this.Context);
                    if (fileInfo.Name == (web.Language.ToString() + ".lng.xml"))
                    {
                        this._currentLanguage = web.Language.ToString();
                    }
                }

                if (this._currentLanguage == "")
                {
                    this._currentLanguage = "1033";
                }

                this._resourceFile = new XmlDocument();
                XmlTextReader reader = new XmlTextReader(this.Page.Server.MapPath(resources + "/" + this._currentLanguage + ".lng.xml"));
                this._resourceFile.Load(reader);
                reader.Close();
            }
            catch (Exception ex)
            {
                AddError(ex);
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="action">新的操作名称</param>
        /// <param name="typeFldName">类别字段名称</param>
        /// <param name="typeID">类别值</param>
        private int AddOperate(string action, int typeID)
        {
            CustomConcatenatedField f = (CustomConcatenatedField)base.Field;
            string  lstID             = f.LookupList;
            SPSite  s         = SPControl.GetContextSite(Context);
            int     itemID    = 0;
            SPWeb   lookupWeb = SPControl.GetContextWeb(Context);
            int     userID    = lookupWeb.CurrentUser.ID;
            SPField typeFld   = GetCascadedField;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(lookupWeb.Site.ID))
                {
                    using (SPWeb web = site.AllWebs[lookupWeb.ID])
                    {
                        SPList lookupList      = web.Lists[new Guid(lstID)];
                        SPListItem addItem     = lookupList.Items.Add();
                        addItem["Title"]       = action;
                        addItem[typeFld.Title] = typeID;
                        addItem[lookupList.Fields.GetFieldByInternalName("Flag").Title] = "11";
                        addItem["Author"]      = userID;
                        web.AllowUnsafeUpdates = true;
                        addItem.Update();
                        web.AllowUnsafeUpdates = false;
                        itemID = addItem.ID;
                    }
                }
            });
            return(itemID);
        }
Esempio n. 4
0
        protected void CopyItem(object sender, EventArgs e)
        {
            int  itemid = Convert.ToInt32(Request.QueryString["ItemId"]);
            Guid listid = new Guid(Request.QueryString["ListId"]);

            SPWeb      sourceweb  = SPControl.GetContextWeb(HttpContext.Current);
            SPList     sourcelist = sourceweb.Lists[listid];
            SPListItem sourceitem = sourcelist.GetItemById(itemid);

            lblListItem.Text = sourceitem.Name;

            TreeNodeContext ctx = new TreeNodeContext(tvSite.SelectedValue);

            SPSite destcol = new SPSite(ctx.SiteCollection);
            SPWeb  destweb = destcol.AllWebs[ctx.WebID];

            if (ctx.IsList)
            {
                SPList     destlist = destweb.Lists[ctx.ListID];
                SPListItem destitem = destlist.Items.Add();

                SPFolder folder = destlist.RootFolder;

                try
                {
                    folder.Files.Add(sourceitem.Name, sourceitem.File.OpenBinary());
                }
                catch (Exception ex)
                {
                    lblStatus.Text = string.Format("Error uploading File {0}", sourceitem.Name);
                }

                lblStatus.Text = string.Format("{0} copied successfully to {1}", sourceitem.Name, destlist.Title);
            }
        }
Esempio n. 5
0
        public override PickerEntity ValidateEntity(PickerEntity needsValidation)
        {
            PickerEntity entity = needsValidation;

            if (!string.IsNullOrEmpty(needsValidation.DisplayText))
            {
                using (SPWeb web = SPControl.GetContextWeb(Context))
                {
                    FieldLookupWithPickerPropertyBag propertyBag = new FieldLookupWithPickerPropertyBag(this.CustomProperty);

                    SPList  list      = web.Lists[propertyBag.ListId];
                    SPQuery queryById = new SPQuery();
                    queryById.Query = string.Format("<Where><Eq><FieldRef Name=\"ID\"/><Value Type=\"Integer\">{0}</Value></Eq></Where>", needsValidation.Key);
                    SPListItemCollection items = list.GetItems(queryById);
                    if (items.Count > 0)
                    {
                        entity = this.GetEntity(items[0]);
                    }
                    else
                    {
                        SPQuery queryByTitle = new SPQuery();
                        queryByTitle.Query = string.Format("<Where><Eq><FieldRef Name=\"{0}\"/><Value Type=\"Text\">{1}</Value></Eq></Where>", propertyBag.FieldId, needsValidation.DisplayText);
                        items = list.GetItems(queryByTitle);
                        if (items.Count > 0)
                        {
                            entity = this.GetEntity(items[0]);
                        }
                    }
                }
            }

            return(entity);
        }
        /// <summary>Initializes a new instance of <see cref="SlkCulture"/>.</summary>
        /// <param name="web">The web to localize.</param>
        public SlkCulture(SPWeb web)
        {
            Resources = new AppResourcesLocal();
            Culture   = System.Threading.Thread.CurrentThread.CurrentUICulture;
            if (web == null && HttpContext.Current != null)
            {
                web = SPControl.GetContextWeb(HttpContext.Current);
            }

            if (web != null)
            {
#if SP2007
                Culture = web.Locale;
#else
                if (web.IsMultilingual)
                {
                    // Just use the current UI culture as set above
                }
                else
                {
                    // Not a multi-lingual site so return the web's locale
                    Culture = web.Locale;
                }
#endif
            }

            Resources.Culture = Culture;
        }
Esempio n. 7
0
        /// <summary>
        /// 返回当前父级下的第一项的ID
        /// </summary>
        /// <param name="lstID"></param>
        /// <param name="fldInterlName"></param>
        /// <param name="fldCascaded"></param>
        /// <param name="cateID"></param>
        /// <returns></returns>
        private int GetListItemsOfFirstID(string lstID, string fldInterlName, string fldCascaded, int cateID)
        {
            SPSite  s          = SPControl.GetContextSite(Context);
            SPWeb   lookupWeb  = SPControl.GetContextWeb(Context);
            SPList  lookupList = lookupWeb.Lists[new Guid(lstID)];
            SPQuery qry        = new SPQuery();

            if (fldCascaded == "")//没有层次级别的分类,直接获取表中的所有数据
            {
                qry.Query = @"";
            }
            else //通过父类ID进行层次级别的标识
            {
                if (cateID > 0)
                {
                    qry.Query = @"<Where><Eq><FieldRef Name='" + fldCascaded + "' LookupId='True' /><Value Type='Lookup'>" + cateID + "</Value></Eq></Where>";
                }
                else
                {
                    qry.Query = @"<Where><IsNull><FieldRef Name='" + fldCascaded + "' /></IsNull></Where>";
                }
            }

            //查阅项列表
            SPListItemCollection items = lookupList.GetItems(qry);
            int id = 0;

            if (items.Count > 0)
            {
                id = items[0].ID;
            }
            return(id);
        }
Esempio n. 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try {
                if (!Page.IsPostBack)
                {
                    FillContent();
                    FillSites();
                    SPWeb currentSite = SPControl.GetContextWeb(Context);
                    if (!currentSite.DoesUserHavePermissions(SPBasePermissions.ManageSubwebs))
                    {
                        newSubsite.Visible = false;
                    }
                    if (!currentSite.DoesUserHavePermissions(SPBasePermissions.ManageLists))
                    {
                        newapp.Visible = false;
                    }
                    lblMessage.Text += "<br>Manage Web: " + currentSite.DoesUserHavePermissions(SPBasePermissions.ManageWeb).ToString();
                    lblMessage.Text += "<br>Manage Lists: " + currentSite.DoesUserHavePermissions(SPBasePermissions.ManageLists).ToString();
                    lblMessage.Text += "<br>Manage Subwebs: " + currentSite.DoesUserHavePermissions(SPBasePermissions.ManageSubwebs).ToString();

                    lblRecycleBinCount.Text = string.Format("({0})", currentSite.RecycleBin.Count.ToString());
                }
            } catch (Exception ex) {
                lblMessage.Text += ex.ToString();
            }
        }
Esempio n. 9
0
        protected void LoadFolderNodes(SPFolder folder, TreeNode folderNode)
        {
            foreach (SPFolder childFolder in folder.SubFolders)
            {
                TreeNode childFolderNode = new TreeNode(childFolder.Name, childFolder.Name, FOLDER_IMG);
                childFolderNode.NavigateUrl = SPControl.GetContextWeb(this.Context).Site.MakeFullUrl(childFolder.Url);
                LoadFolderNodes(childFolder, childFolderNode);
                folderNode.ChildNodes.Add(childFolderNode);
            }


            foreach (SPFile file in folder.Files)
            {
                TreeNode fileNode;
                if (file.CustomizedPageStatus == SPCustomizedPageStatus.Uncustomized)
                {
                    fileNode = new TreeNode(file.Name, file.Name, GHOSTED_FILE_IMG);
                }
                else
                {
                    fileNode = new TreeNode(file.Name, file.Name, UNGHOSTED_FILE_IMG);
                }
                fileNode.NavigateUrl = SPControl.GetContextWeb(this.Context).Site.MakeFullUrl(file.Url);
                folderNode.ChildNodes.Add(fileNode);
            }
        }
Esempio n. 10
0
        public static string GetPersonalPageUserName()
        {
            string userName;

            SPWeb web = SPControl.GetContextWeb(HttpContext.Current);

            SPServiceContext   spServiceContext   = SPServiceContext.GetContext(web.Site);
            UserProfileManager userProfileManager = new UserProfileManager(spServiceContext);

            string accountname = HttpContext.Current.Request.Params.Get("accountname");

            if (accountname == null)
            {
                userName = web.CurrentUser.Name;
            }
            else
            {
                if (userProfileManager.UserExists(accountname))
                {
                    UserProfile userProfile = userProfileManager.GetUserProfile(accountname);
                    userName = userProfile.DisplayName;
                }
                else
                {
                    userName = "";
                }
            }

            return(userName);
        }
Esempio n. 11
0
        protected override void Render(HtmlTextWriter writer)
        {
            HttpContext context = HttpContext.Current;
            SPWeb       site    = SPControl.GetContextWeb(context);
            SPUser      user    = site.CurrentUser;
            string      output  = string.Format("Hi {0} - Welcome to the site {1}", user.Name, site.Name);

            writer.Write(output);
        }
        private void SetTargetWeb()
        {
            listTargetWeb.Items.Clear();
            List <ListItem> str = new List <ListItem>();

            //using (SPSite _site = SPControl.GetContextSite(this.Context)) {
            SPSite          _site          = SPControl.GetContextSite(this.Context);
            SPWebCollection _webCollection = _site.AllWebs;
            string          contextWebId   = SPControl.GetContextWeb(this.Context).ID.ToString();

            foreach (SPWeb web in _webCollection)
            {
                try
                {
                    if (web.DoesUserHavePermissions(
                            SPBasePermissions.ViewPages | SPBasePermissions.OpenItems | SPBasePermissions.ViewListItems))
                    {
                        str.Add(new ListItem(web.Title, web.ID.ToString()));
                    }
                }
                catch (Exception ex) { LoggingService.WriteTrace(Area.EPMLiveCore, Categories.EPMLiveCore.IntegrationCore, TraceSeverity.Medium, ex.ToString()); }
                finally { if (web != null)
                          {
                              web.Dispose();
                          }
                }
            }
            if (str.Count > 0)
            {
                str.Sort(delegate(ListItem item1, ListItem item2)
                {
                    return(item1.Text.CompareTo(item2.Text));
                });

                listTargetWeb.Items.AddRange(str.ToArray());
                ListItem bitem = null;
                if (!string.IsNullOrEmpty(TargetWebId))
                {
                    bitem = listTargetWeb.Items.FindByValue(TargetWebId);
                }
                else
                {
                    bitem = listTargetWeb.Items.FindByValue(contextWebId);
                }
                if (bitem != null)
                {
                    listTargetWeb.SelectedIndex = listTargetWeb.Items.IndexOf(bitem);
                }
                else
                {
                    listTargetWeb.SelectedIndex = 0;
                }

                SetTargetList(listTargetWeb.SelectedItem.Value, true);
            }
        }
Esempio n. 13
0
        private void InitializeApplication()
        {
            UrlQuery query = new UrlQuery(this.Page.Request.Url.ToString());

            ForumApplication.Instance.BasePath          = SPEncode.UrlEncodeAsUrl(query.Url);
            ForumApplication.Instance.Title             = this.Name;
            ForumApplication.Instance.ForumCache        = this.Page.Cache;
            ForumApplication.Instance.ClassResourcePath = this.ClassResourcePath;
            ForumApplication.Instance.SpUser            = SPControl.GetContextWeb(Context).CurrentUser;
            ForumApplication.Instance.AppPoolUser       = SPControl.GetContextSite(Context).OpenWeb().CurrentUser;
            ForumApplication.Instance.SpWeb             = SPControl.GetContextSite(Context).OpenWeb();
        }
        /// <summary>
        ///     This is the standard method for adding controls to a web part.
        /// </summary>
        protected override void CreateChildControls()
        {
            ddlGroup = new DropDownList();
            SPWeb             web    = SPControl.GetContextWeb(Context);
            SPGroupCollection groups = web.SiteGroups;

            for (int idx = 0; idx < groups.Count; idx++)
            {
                ddlGroup.Items.Add(groups[idx].Name);
            }
            this.Controls.Add(ddlGroup);
        }
Esempio n. 15
0
        protected override void CreateChildControls()
        {
            try
            {
                if (!this.Page.IsPostBack)
                {
                    string test = "Test";
                }

                SPWeb topWeb = SPControl.GetContextWeb(this.Context).Site.RootWeb;

                ds = new SPHierarchyDataSourceControl();

                ds.Web               = topWeb;
                ds.RootWebId         = topWeb.Site.RootWeb.ID.ToString();
                ds.RootContextObject = null;
                //ds.RootContextObject = "Web";

                ds.ID = "TreeViewDataSource";
                ds.IncludeDiscussionFolders = true;
                ds.ShowListChildren         = true;
                ds.ShowDocLibChildren       = true;
                ds.ShowFolderChildren       = true;
                ds.DataBind();
                Controls.Add(ds);

                tvw                             = new SPTreeView();
                tvw.ID                          = "WebTreeView";
                tvw.ShowLines                   = false;
                tvw.DataSourceID                = "TreeViewDataSource";
                tvw.ExpandDepth                 = 1;
                tvw.EnableClientScript          = true;
                tvw.EnableViewState             = true;
                tvw.NodeStyle.CssClass          = "ms-navitem";
                tvw.NodeStyle.HorizontalPadding = 2;
                tvw.SelectedNodeStyle.CssClass  = "ms-tvselected";
                tvw.SkipLinkText                = "";
                tvw.NodeIndent                  = 12;
                tvw.ExpandImageUrl              = "/_layouts/images/tvplus.gif";
                tvw.CollapseImageUrl            = "/_layouts/images/tvminus.gif";
                tvw.NoExpandImageUrl            = "/_layouts/images/tvblank.gif";
                tvw.TreeNodeExpanded           += Node_Expand;
                Controls.Add(tvw);
                //tvw.DataBind();

                base.CreateChildControls();
            }
            catch (Exception e)
            {
                string exp = "e.ToString";
            }
        }
        //</Snippet3>
        //<Snippet4>
        protected void Button1_Click(object sender, EventArgs e)
        {
            SPCalendarItemCollection items = new SPCalendarItemCollection();
            SPWeb thisWeb = SPControl.GetContextWeb(Context);

            foreach (ListItem item in CheckBoxList1.Items)
            {
                if (item.Selected == true)
                {
                    SPList   calendarList = thisWeb.Lists[item.Text];
                    DateTime dtStart      = DateTime.Now.AddDays(-7);
                    DateTime dtEnd        = dtStart.AddMonths(1).AddDays(7);
                    SPQuery  query        = new SPQuery();
                    query.Query = String.Format(
                        "<Query>" +
                        "<Where><And>" +
                        "<Geq><FieldRef Name=\"{0}\" />" +
                        "<Value Type=\"DateTime\">{1}</Value></Geq>" +
                        "<Leq><FieldRef Name=\"{0}\" />" +
                        "<Value Type=\"DateTime\">{2}</Value></Leq>" +
                        "</And></Where><OrderBy><FieldRef Name=\"{0}\" /></OrderBy>" +
                        "</Query>",
                        "Start Time",
                        dtStart.ToShortDateString(),
                        dtEnd.ToShortDateString());

                    foreach (SPListItem listItem in calendarList.GetItems(query))
                    {
                        SPCalendarItem calItem = new SPCalendarItem();
                        calItem.ItemID        = listItem["ID"].ToString();
                        calItem.Title         = listItem["Title"].ToString();
                        calItem.CalendarType  = Convert.ToInt32(SPCalendarType.Gregorian);
                        calItem.StartDate     = (DateTime)listItem["Start Time"];
                        calItem.ItemID        = listItem.ID.ToString();
                        calItem.WorkSpaceLink = String.Format(
                            "/Lists/{0}/DispForm.aspx", calendarList.Title);
                        calItem.DisplayFormUrl = String.Format(
                            "/Lists/{0}/DispForm.aspx", calendarList.Title);
                        calItem.EndDate     = (DateTime)listItem["End Time"];
                        calItem.Description = listItem["Description"].ToString();
                        if (listItem["Location"] != null)
                        {
                            calItem.Location = listItem["Location"].ToString();
                        }
                        items.Add(calItem);
                    }
                    MonthlyCalendarView1.DataSource = items;
                }
            }
        }
        protected void BindRedmineData()
        {
            string userName = WebPartsHelper.GetPersonalPageUserName();

            SPWeb web = SPControl.GetContextWeb(HttpContext.Current);
            AppSettingsSection appSettings = WebPartsHelper.GetWebAppSettings(web);

            RedmineData.InitParams(appSettings);

            List <RedmineIssue> issuesByUser = RedmineData.GetUserIssuesAndSetCache(userName);
            Array issuesArrayForGridView     = RedmineData.ConvertRedmineIssuesToArrayForGridView(issuesByUser);

            RedmineGridView.PagerTemplate = null;
            RedmineGridView.DataSource    = issuesArrayForGridView;
            RedmineGridView.DataBind();
        }
        private void SetTargetWeb()
        {
            listTargetWeb.Items.Clear();
            List <ListItem> str = new List <ListItem>();

            SPSite _site = SPControl.GetContextSite(this.Context);

            SPWebCollection _webCollection = _site.AllWebs;
            string          contextWebId   = SPControl.GetContextWeb(this.Context).ID.ToString();

            foreach (SPWeb web in _webCollection)
            {
                if (web.DoesUserHavePermissions(
                        SPBasePermissions.ViewPages | SPBasePermissions.OpenItems | SPBasePermissions.ViewListItems))
                {
                    str.Add(new ListItem(web.Title, web.ID.ToString()));
                }
            }
            if (str.Count > 0)
            {
                str.Sort(delegate(ListItem item1, ListItem item2)
                {
                    return(item1.Text.CompareTo(item2.Text));
                });

                listTargetWeb.Items.AddRange(str.ToArray());
                ListItem bitem = null;
                if (!string.IsNullOrEmpty(TargetWebId))
                {
                    bitem = listTargetWeb.Items.FindByValue(TargetWebId);
                }
                else
                {
                    bitem = listTargetWeb.Items.FindByValue(contextWebId);
                }
                if (bitem != null)
                {
                    listTargetWeb.SelectedIndex = listTargetWeb.Items.IndexOf(bitem);
                }
                else
                {
                    listTargetWeb.SelectedIndex = 0;
                }

                SetTargetList(listTargetWeb.SelectedItem.Value, true);
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            // ensure the user is an administrator, then execute the remaining code within a
            // LearningStorePrivilegedScope (which grants full access to database views)
            if (!SPFarm.Local.CurrentUserIsAdministrator())
            {
                throw new UnauthorizedAccessException(
                          "Access is denied. Only adminstrators can access this page.");
            }
            using (new LearningStorePrivilegedScope())
            {
                // skip the code below during postback since <OriginalInstructor> will have been
                // populated from view state already
                if (IsPostBack)
                {
                    return;
                }

                // populate the <OriginalInstructor> drop-down list with the names and SLK user
                // identifiers of all users who are instructors on any assignments in the current
                // SharePoint site collection
                using (SPWeb spWeb = SPControl.GetContextWeb(HttpContext.Current))
                {
                    SlkStore           slkStore = SlkStore.GetStore(spWeb);
                    LearningStoreJob   job      = slkStore.LearningStore.CreateJob();
                    LearningStoreQuery query    = slkStore.LearningStore.CreateQuery(
                        "AllAssignmentInstructors");
                    query.SetParameter("SPSiteGuid", spWeb.Site.ID);
                    query.AddColumn("InstructorName");
                    query.AddColumn("InstructorId");
                    query.AddSort("InstructorName", LearningStoreSortDirection.Ascending);
                    job.PerformQuery(query);
                    DataRowCollection rows = job.Execute <DataTable>().Rows;
                    OriginalInstructor.Items.Add(String.Empty);
                    foreach (DataRow row in rows)
                    {
                        ListItem listItem = new ListItem();
                        listItem.Text = (string)row["InstructorName"];
                        UserItemIdentifier originalInstructorId =
                            new UserItemIdentifier((LearningStoreItemIdentifier)row["InstructorId"]);
                        listItem.Value = originalInstructorId.GetKey().ToString(
                            CultureInfo.InvariantCulture);
                        OriginalInstructor.Items.Add(listItem);
                    }
                }
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Relative url for zoom builder
        /// </summary>
        /// <returns>The relative Url</returns>
        private static string ZoomBuilderRelativeUrl()
        {
            HttpContext current  = HttpContext.Current;
            SPWeb       web      = SPControl.GetContextWeb(current);
            string      relative = web.ServerRelativeUrl;

            if (relative == "/")
            {
                relative = "/_layouts/zoombldr.aspx";
            }
            else
            {
                relative += "/_layouts/zoombldr.aspx";
            }

            return(SPEncode.UrlEncodeAsUrl(relative));
        }
Esempio n. 21
0
        private void FillSites()
        {
            DefineSubsitesTable();
            SPWeb           currentSite = SPControl.GetContextWeb(Context);
            SPWebCollection subSites    = currentSite.GetSubwebsForCurrentUser();

            foreach (SPWeb site in subSites)
            {
                DataRow dr = dtSubsites.NewRow();
                dr["Title"]       = site.Title;
                dr["Description"] = site.Description;
                dr["URL"]         = site.Url;
                dtSubsites.Rows.Add(dr);
            }
            gvSubsites.DataSource = dtSubsites;
            gvSubsites.DataBind();
        }
Esempio n. 22
0
 ///<summary>Finds the role definition to use when filtering the webs by permission.</summary>
 void FindPermissionToUse()
 {
     if (!string.IsNullOrEmpty(permission))
     {
         try
         {
             definition = SPControl.GetContextWeb(Context).RoleDefinitions[permission];
             if (definition == null)
             {
                 throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, Strings.PermissionNotExist, permission));
             }
         }
         catch (SPException)
         {
             throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, Strings.PermissionNotExist, permission));
         }
     }
 }
Esempio n. 23
0
        public PickerEntity GetEntityById(int id)
        {
            PickerEntity entity = null;

            if (id > 0)
            {
                using (SPWeb web = SPControl.GetContextWeb(Context))
                {
                    SPList  list      = web.Lists[new FieldLookupWithPickerPropertyBag(this.CustomProperty).ListId];
                    SPQuery queryById = new SPQuery();
                    queryById.Query = string.Format("<Where><Eq><FieldRef Name=\"ID\"/><Value Type=\"Integer\">{0}</Value></Eq></Where>", id);
                    SPListItemCollection items = list.GetItems(queryById);
                    if (items.Count > 0)
                    {
                        entity = this.GetEntity(items[0]);
                    }
                }
            }

            return(entity);
        }
Esempio n. 24
0
 protected override void OnLoad(EventArgs e)
 {
     try
     {
         SPWeb contextWeb = SPControl.GetContextWeb(this.Context);
         if ((contextWeb != null) && (contextWeb.UIVersion <= 3))
         {
             this._incompatibleUIVersion = true;
             return;
         }
         Type baseType = this.Page.GetType().BaseType;
         if ((baseType == typeof(WebPartPage)) || (baseType == typeof(Page)))
         {
             Control control = this.findControl(this.Page, "LTViewSelectorMenu");
             if (control != null)
             {
                 if (!control.Visible)
                 {
                     typeof(ListTitleViewSelectorMenu).GetField("m_wpSingleInit", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(control, true);
                     typeof(ListTitleViewSelectorMenu).GetField("m_wpSingle", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(control, true);
                 }
                 this._ltvsmAlreadyPresent = true;
             }
             else
             {
                 this._visible = true;
             }
         }
         else if (baseType == typeof(WikiEditPage))
         {
             this._visible = true;
         }
     }
     catch (Exception exception)
     {
         this._trace = this._trace + exception.ToString();
     }
     base.OnLoad(e);
 }
        /// <summary>Renders the web part.</summary>
        protected override void RenderContents(HtmlTextWriter writer)
        {
            if (ValidateProperties())
            {
                SPListItemCollection items = FindDocuments();

                if (items != null && items.Count > 0)
                {
                    writer.Write("<ul class=\"slk-sa\">");

                    foreach (SPListItem item in items)
                    {
                        if (item.File != null)
                        {
                            string url = "{0}{1}frameset/frameset.aspx?ListId={2}&ItemId={3}&SlkView=Execute&play=true";
                            string serverRelativeUrl = SPControl.GetContextWeb(Context).ServerRelativeUrl;
                            url = string.Format(CultureInfo.InvariantCulture, url, serverRelativeUrl, Constants.SlkUrlPath, item.ParentList.ID.ToString("B"), item.ID);

                            string title = item.Title;
                            if (string.IsNullOrEmpty(title))
                            {
                                title = item.Name;
                            }

                            writer.Write("<li><a href=\"{0}\" target=\"_blank\">{1}</a></li>", url, HttpUtility.HtmlEncode(title));
                        }
                    }

                    writer.Write("</ul>");
                }
                else
                {
                    writer.Write("<p class=\"ms-vb\">{0}</p>", HttpUtility.HtmlEncode(culture.Resources.SelfAssignPartNoItems));
                }
            }

            RenderErrors(writer);
        }
Esempio n. 26
0
        /// <summary>
        /// overrides the CreateChildControls of webpart
        /// </summary>
        protected override void CreateChildControls()
        {
            //debug.Add("CreateChildControls");
            base.CreateChildControls();

            //if the url is not given
            if (string.IsNullOrEmpty(StartSite))
            {
                SPWeb web = SPControl.GetContextWeb(Context);
                StartSite = web.Url;
            }

            if (PageSize < 1)
            {
                Controls.Add(new LiteralControl("The number of items per page is not valid, Please enter a number greater than 0."));
            }
            else
            {
                BuildDataTable();
                BuildForm();
                FindAccessibleSubSites();
            }
        }
 /// <summary>
 /// Handles the Load event of the Page control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 /// <exception cref="System.ApplicationException">Page_Load exception:  + ex.Message</exception>
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         if (!IsPostBack)
         {
             m_WarehouseDropDownList.DataSource = from _idx in EDC.Warehouse
                                                  orderby _idx.Title ascending
                                                  select new { Title = _idx.Title, ID = _idx.Id.Value };
             m_WarehouseDropDownList.DataTextField  = "Title";
             m_WarehouseDropDownList.DataValueField = "ID";
             m_WarehouseDropDownList.DataBind();
             //This best practice addresses the issue identified by the SharePoint Dispose Checker Tool as SPDisposeCheckID_210
             SPWeb   _currentWeb = SPControl.GetContextWeb(this.Context);
             Partner _Partner    = Partner.FindForUser(EDC, _currentWeb.CurrentUser);
             if (_Partner != null)
             {
                 m_WarehouseDropDownList.Select(_Partner.Partner2WarehouseTitle);
             }
             else
             {
                 m_WarehouseDropDownList.SelectedIndex = 0;
             }
             m_Calendar.VisibleDate  = DateTime.Today;
             m_Calendar.SelectedDate = DateTime.Today;
         }
         m_InterconnectionDataTable_TimeSlotTimeSlot = new InterconnectionDataTable <TimeSlotTimeSlot>(typeof(TimeSlot).Name);
         m_Calendar.DayRender                += new DayRenderEventHandler(m_Calendar_DayRender);
         m_Calendar.SelectionChanged         += new EventHandler(m_Calendar_SelectionChanged);
         m_Calendar.VisibleMonthChanged      += new MonthChangedEventHandler(m_Calendar_VisibleMonthChanged);
         m_TimeSlotList.SelectedIndexChanged += new EventHandler(m_TimeSlotList_SelectedIndexChanged);
     }
     catch (Exception ex)
     {
         throw new ApplicationException("Page_Load exception: " + ex.Message, ex);
     }
 }
        private void loadResourceFileStrings()
        {
            try
            {
                var resources             = getResourceDirectory();
                var directoryInfo         = new DirectoryInfo(Page.Server.MapPath(resources));
                var languageFileInfoArray = directoryInfo.GetFiles(LanguageFilter);

                SPWeb web;
                for (var n = 0; n < languageFileInfoArray.Length; n++)
                {
                    var fileInfo = languageFileInfoArray[n];
                    web = SPControl.GetContextWeb(Context);
                    if (fileInfo.Name == (web.Language + ".lng.xml"))
                    {
                        _currentLanguage = web.Language.ToString();
                    }
                }

                if (_currentLanguage == "")
                {
                    _currentLanguage = "1033";
                }

                _resourceFile = new XmlDocument();
                var reader =
                    new XmlTextReader(
                        Page.Server.MapPath(string.Format("{0}/{1}.lng.xml", resources, _currentLanguage)));
                _resourceFile.Load(reader);
                reader.Close();
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
        //</Snippet2>
        //<Snippet3>
        protected void Page_Load(object sender, EventArgs e)
        {
            MonthlyCalendarView1 = new MonthlyCalendarView();
            this.Controls.Add(MonthlyCalendarView1);
            SPCalendarItemCollection items = new SPCalendarItemCollection();
            SPWeb thisWeb = SPControl.GetContextWeb(Context);

            if (CheckBoxList1.Items.Count == 0)
            {
                foreach (SPList listItem in thisWeb.Lists)
                {
                    if (listItem.BaseTemplate == SPListTemplateType.Events)
                    {
                        CheckBoxList1.Items.Add(new ListItem(listItem.Title));
                    }
                }
            }
            MonthlyCalendarView1.ItemTemplateName =
                "CalendarViewMonthItemTemplate";
            MonthlyCalendarView1.ItemAllDayTemplateName =
                "CalendarViewMonthItemAllDayTemplate";
            MonthlyCalendarView1.ItemMultiDayTemplateName =
                "CalendarViewMonthItemMultiDayTemplate";
        }
Esempio n. 30
0
        public void LoadData(string MensagemSucesso, string MensagemValidacao, string MensagemInformacao)
        {
            this._mensagemSucesso    = MensagemSucesso;
            this._mensagemValidacao  = MensagemValidacao;
            this._mensagemInformacao = MensagemInformacao;
            try
            {
                using (SPWeb web = SPControl.GetContextWeb(Context))
                {
                    using (ModelDataContext _db = new ModelDataContext(web.Url))
                    {
                        var _listEnquetes = (from x in _db.ListaDeRespostas.ToList()
                                             where x.AutorId == SPContext.Current.Web.CurrentUser.ID
                                             select x.Enquete).ToList();

                        foreach (var item in _db.Enquete.Where(x => x.DataDeVencimento >= DateTime.Now).ToList())
                        {
                            if (!_listEnquetes.Contains(item))
                            {
                                CarregarEnquete(item);
                                this.btnEnviar.Visible = true;
                                break;
                            }
                            else
                            {
                                LimparTela(item);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }