Get Personal SPWeb Object(Mysite Object)获取MOSS个人站点的SPWeb对象

        /// <summary>
        /// Author:李曦光(Bruce Lee)
        /// Created Time:2008-9-16
        /// Description:get personal web site.
        /// Mender:
        /// Modify Time:
        /// Modify Description:
        /// </summary>
        /// <param name="strAccount">personal account, for example:"satyambrucelee\\Administrator",个人账号,例如:"satyambrucelee\\Administrator"</param>
        /// <param name="strPersonalSiteHost">personal site host url, for example:http://satyambrucelee:8086,个人站点宿主url,例如:http://satyambrucelee:8086</param>
        /// <returns></returns>
        public SPWeb GetPersonalWeb(string strAccount,string strPersonalSiteHost)
        {
            SPSite mySite = null;
            SPWeb myWeb = null;
            SPSite spPersonalSite = null;
            try
            {
                spPersonalSite = new SPSite(strPersonalSiteHost);
                ServerContext serverContext = ServerContext.GetContext(spPersonalSite);
                UserProfileManager userProfileManager = new UserProfileManager(serverContext);
                UserProfile userProfile = userProfileManager.GetUserProfile(strAccount);

                mySite = userProfile.PersonalSite;
                myWeb = mySite.OpenWeb();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                myWeb.Dispose();
                mySite.Dispose();
                spPersonalSite.Dispose();
            }
            return myWeb;
        }

你可能感兴趣的:(object)