现在的位置: 首页 > 综合 > 正文

sharepoint 一些杂乱的code

2013年01月19日 ⁄ 综合 ⁄ 共 1693字 ⁄ 字号 评论关闭

//根据AD里面的用户名获取头像图片[需要有域名]
    private string GetPictureUrl(string loginName)
    {
        loginName = Environment.UserDomainName + "\\" + loginName;
        SPSite site = null;
        SPWeb web = null;
        using (site = new SPSite(mySiteUrl))
        {
            using (web = site.RootWeb)
            {
                web.AllowUnsafeUpdates = true;
                ServerContext ctx = ServerContext.GetContext(site);
                UserProfileManager profileMgr = new UserProfileManager(ctx);
                //避免报 '对象状态失效' [如果实在不行就在提升权限]
                if (HttpContext.Current != null)
                {
                    if (HttpContext.Current.Items["HttpHandlerSPWeb"] == null)
                    {
                        HttpContext.Current.Items["HttpHandlerSPWeb"] = web;
                    }
                    if (HttpContext.Current.Items["Microsoft.Office.ServerContext"] == null)
                    {
                        HttpContext.Current.Items["Microsoft.Office.ServerContext"] = ctx;
                    }
                }
                if (profileMgr.UserExists(loginName))
                {
                    Microsoft.Office.Server.UserProfiles.UserProfile up = profileMgr.GetUserProfile(loginName);
                    //sharepoint 中使用默认头像时,他的值为null
                    if (!string.IsNullOrEmpty(up[PropertyConstants.PictureUrl].Value as string))
                    {
                        return up[PropertyConstants.PictureUrl].Value.ToString();
                    }
                    else
                    {
                        return "~/_layouts/images/no_pic.gif";
                    }
                }
                return "~/_layouts/images/no_pic.gif";
            }
        }

    }

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jinho/archive/2010/01/25/5253529.aspx

抱歉!评论已关闭.