Subscribe:

Labels

Sunday, December 11, 2011

check the condition the group in exist or not


these 2 metod are using for check the condition the group in exist or not

private bool isGroupAlreadyExist(SPWeb web, string groupName)
        {
            bool isExist = false;

            try
            {
                SPGroup group = web.SiteGroups[groupName];
                isExist = true;
            }
            catch (SPException)
            {
                isExist = false;
            }
            catch (Exception)
            {
                isExist = false;
            }
            return isExist;
        }


if (!isGroupAlreadyExist(web, groupName))
                {
                   
                }


get spsuer using object model

this is for get spuser... code using object model

 /// <summary>
        /// Returns the SPUser Object built based on the OOTB people or groups field type of sharepoint.
        /// Get SPUser Object from a SharePoint list item people or group field value.
        /// Can be used to get the user object properties, e.g. email of the user.
        /// </summary>
        /// <param name="spListItem">Source list item</param>
        /// <param name="fieldName">column/field name, e.g., "PersResponsible"</param>
        /// <returns></returns>

        public SPUser GetSPUserObject(SPListItem spListItem, String fieldName)
        {
            SPUser spUser = null;
            try
            {
                if (fieldName != string.Empty)
                {
                    SPFieldUser field = spListItem.Fields[fieldName] as SPFieldUser;
                    if (field != null && spListItem[fieldName] != null)
                    {
                        SPFieldUserValue fieldValue = field.GetFieldValue(spListItem[fieldName].ToString()) as SPFieldUserValue;
                        if (fieldValue != null)
                        {
                            spUser = fieldValue.User;

                        }
                    }
                }
            }
            catch (Exception ex)
            {
              
            }

            return spUser;
        }

Customize Top Navigation Bar - Horizontal Orientation for second level


Add Css in core4.css

.s4-toplinks {
    padding-bottom: 20px; /* create space to fit the 2nd level nav */
    position: relative;
}
 
.s4-toplinks .s4-tn li {
    position: static !important; /* 2nd level will be positioned relative to .s4-toplinks container */
float:left;
}
 


Add this in Master page 


<SharePoint:AspMenu
 ID="TopNavigationMenuV4"
 Runat="server"
 EnableViewState="false"
 DataSourceID="topSiteMap"
 AccessKey="<%$Resources:wss,navigation_accesskey%>"
 UseSimpleRendering="true"
 UseSeparateCss="false"
 Orientation="Horizontal"
 StaticDisplayLevels="2"
 MaximumDynamicDisplayLevels="4"
 SkipLinkText=""
 CssClass="s4-tn"/>

<Template_Controls>
<asp:SiteMapDataSource
 ShowStartingNode="true"(change here)
 SiteMapProvider="SPSiteMapProvider"(change here)
 id="topSiteMap"
 runat="server"
 />



Create a mysite(personal site) Using the Object Model

Below code is using object model creating the my sites dynamically.


            SPSite site = new SPSite("http://win-rgqt3bch3nk:22929/sites/Test");

            SPWeb web = site.OpenWeb();
            // SPWeb web = SPContext.Current.Web;


            web.AllowUnsafeUpdates = true;

         
            if (ApproveitemId > 0)
            {
                SPList thislist = web.Lists["Requests"];
                SPListItem item = thislist.Items.GetItemById(ApproveitemId);
                string AStatus = item["Approval_Status"].ToString();
                string strYes = "Yes";
                if (AStatus == strYes)
                {
                    string mysiteusername = item["Username"].ToString();
                     //SPUser mysiteuname = web.AllUsers[mysiteusername];

                    SPSecurity.RunWithElevatedPrivileges(delegate()
                         {
                             using (SPSite spSite = new SPSite("http://win-rgqt3bch3nk:38562"))
                             {
                                 spSite.AllowUnsafeUpdates = true;
                                 SPContext.Current.Web.AllowUnsafeUpdates = true;
                                 SPServiceContext siteContext = SPServiceContext.GetContext(spSite);
                                 //UserProfileManager up = new UserProfileManager(siteContext,true);
                                 UserProfileManager up = new UserProfileManager(siteContext);
                                 //string sAccount = "WIN-RGQT3BCH3NK\\test1";
                                 //UserProfile uprof = up.GetUserProfile(sAccount.Trim());
                                 UserProfile uprof = up.GetUserProfile(mysiteusername);
                                 uprof.CreatePersonalSite();
                             }
                         });
                }
            }
         
        }