• 一个简单的欢迎webpart


     
       
    using System;
    using System.ComponentModel;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    using Microsoft.SharePoint.WebPartPages;
    
    namespace SOASPProject.welcome
    {
        [ToolboxItemAttribute(false)]
        public class welcome : System.Web.UI.WebControls.WebParts.WebPart
        {
            /// <summary>
            /// 构造函数
            /// </summary>
            #region public welcome()
            public welcome()
            {
            }
            #endregion
    
            /// <summary>
            /// 创建子控件
            /// </summary>
            #region protected override void CreateChildControls()
            protected override void CreateChildControls()
            {
                base.CreateChildControls();
    
                // TODO: add custom rendering code here.
                // Label label = new Label();
                // label.Text = "Hello World";
                // this.Controls.Add(label);
            }
            #endregion
    
            /// <summary>
            /// 重写控件输出
            /// </summary>
            /// <param name="writer"></param>
            #region protected override void Render(HtmlTextWriter writer)
            protected override void Render(HtmlTextWriter writer)
            {
                string strWelcomeInfo = string.Empty;
                string strTitle = string.Empty;
                string strDepartment = string.Empty;
    
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite spSite = new SPSite(SPContext.Current.Site.Url))
                    {
                        SPUser spUser = SPContext.Current.Web.CurrentUser;
                        SPList spLstUser = null;
                        //获取当前用户和当前用户所对应的USER列表中的记录
                        foreach (SPList spLst in spSite.RootWeb.Lists)
                        {
                            if (spLst.Title.Equals("用户信息列表"))
                            {
                                spLstUser = spLst;
                            }
                        }
    
                        //读取用户信息并绑定到页面
                        SPListItem spLstItem = spLstUser.GetItemById(spUser.ID);
    
                        //获取数据
                        strTitle = spLstItem["Title"] != null ? spLstItem["Title"].ToString() : string.Empty;
                        strDepartment = spLstItem["Department"] != null ? spLstItem["Department"].ToString() : string.Empty;
                    }
                });
    
                strWelcomeInfo += "<table class='WelcomeTable'><tr>";
                strWelcomeInfo += "<td class='WelcomeTdImage'><td>";
                strWelcomeInfo += "<td class='WelcomeTd'>欢迎:[" + strDepartment + "]" + strTitle + "    今天是:" + DateTime.Now.ToString("yyyy年MM月dd日") + "<td>";
                strWelcomeInfo += "</tr></table>";
    
                writer.Write(strWelcomeInfo);
            }
            #endregion
        }
    }
  • 相关阅读:
    bzoj 1022: [SHOI2008]小约翰的游戏John anti_nim游戏
    spoj gss2 : Can you answer these queries II 离线&&线段树
    hduoj 1077 Catching Fish 求单位圆最多覆盖点个数
    HDUOJ Clear All of Them I 状压DP
    bzoj 1013: [JSOI2008]球形空间产生器sphere 高斯消元
    bzoj 1006: [HNOI2008]神奇的国度 弦图的染色问题&&弦图的完美消除序列
    Cocos2d-x Lua中生命周期函数
    Cocos2d-x Lua中使用标签
    Cocos2d-x Lua中Sprite精灵类
    Cocos2d-x Lua Node与Node层级架构
  • 原文地址:https://www.cnblogs.com/IsNull/p/1944804.html
Copyright © 2020-2023  润新知