CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Mark DiGiovanni

Software Development and Supporting Technologies

February 2005 - Posts

  • Shorter hours in software

    It seems that shorter work days are the new trend in the software industry.  I think EA helped bring this to the forefront, but companies may not be all to blame.

    A tough-guy culture among coders also seems to have been a factor. Last year, the International Game Developers Association cited this as a reason for horrible working conditions in the computer game world.

    "Developers are sometimes just as much to blame for submitting themselves to extreme working conditions, adopting a macho bravado in hopes of 'proving' themselves worthy for the industry," the professional group's board said in a statement.

    Does working overtime produce more work?

    Research indicates that long hours don't translate into heaps of extra work. Consultant DeMarco has studied productivity data and concluded that workers putting in 44 hours per week generate the same amount of work as those who put in 36 or 37 hours.

    "There's nothing to be gained from the extra hours," he said. DeMarco argues that there are limits to how much people can churn out without adequate breaks, and companies with cultures of long days tend not to run meetings in a disciplined fashion.

    Read on here.

    —Mark

  • Determine User Site Group (Role) Membership in SharePoint 2003

    Since there is no method to test whether a user is a member of a specific SharePoint Site Group such as Reader, Member, etc., use the following method:

            private bool IsCurrentUserInRole(string role)
            {
                bool inRole= false;

                SPWeb rootWeb = SPControl.GetContextSite(Context).RootWeb;
                SPRole  spRole = rootWeb.Roles[role];
                SPUser currentUser = rootWeb.CurrentUser;
       
                foreach(SPUser roleUser in spRole.Users)
                {
                    if(roleUser.ID.Equals(currentUser.ID))
                    {
                        inRole= true;
                        break;
                    }
                }

                return inRole;
            }

    A similar loop will have to be used to remove a user from a role.  This avoids having to trap an exception that gets thrown when the user cannot be found in the role collection.

    Update:  I found this post.  Take a look.

    --Mark

  • How To Retrieve a User's Profile in SharePoint 2003

    I am currently building a Web Part for our internal SharePoint 2003 portal site that will return the employee directory complete with photo, email address, and home, work, and cell phone numbers. To do this, the web part needs to access to the users profile. Here is the C# code needed to get the user profiles. 

    *The below code does not represent a complete web part*

    First, make sure that your web part has the appropriate code access security settings such as the SharePointPermission with the following setting: ObjectModel=True. For more information on Code Access Security and SharePoint, click here.

    Add the following using statements after the assemblies are referenced.

    using Microsoft.SharePoint.Portal;
    using Microsoft.SharePoint.Portal.Topology;
    using Microsoft.SharePoint.Portal.UserProfiles;
    The root site will have to be retrieved to get the collection of users. Use the following method to get the base URL.

    private string GetRootUrl()
    {

    string url = Context.Request.Url.GetLeftPart(UriPartial.Authority) + this.ResolveUrl( Context.Request.ApplicationPath);
    return url;

    }

    *NOTE* If you are accessing the portal site via http://localhost/, you must add http://localhost/ as an alias for the site.

    //Get the root URL and the PortalContext.
    string url = GetRootUrl();
    SPSite rootSite = SPControl.GetContextSite(Context);
    PortalContext portalContext =
    null;
    Uri uri =
    new Uri(url);

    //Get the collection of portal sites by the URL.
    TopologyManager topologyManager = new TopologyManager();
    PortalSiteCollection sites = topologyManager.PortalSites;
    portalContext = PortalApplication.GetContext(sites[uri]);

    //Get all the users that have access.
    SPUserCollection allUsers = rootSite.RootWeb.AllUsers;
    UserProfileManager upm =
    new UserProfileManager(portalContext);

    //Loop through the users to get their profile.
    foreach (SPUser user in allUsers)
    {

    //Do whatever needs to be done with the following properties.
    UserProfile up = upm.GetUserProfile(user.LoginName);

    string fullName = up["PreferredName"].ToString();
    string emailAddress = up["WorkEmail"].ToString();
    string homePhone = up["HomePhone"].ToString();
    string cellPhone = up["MobilePhone"].ToString();

    }

    To see a list of property names available to you, navigate here: Site Settings > Manage profile Database > View profile properties.

    For additional resources on SharePoint, visit the following sites:

    SharePoint and Code Access Security
    Lamont Harrington's SharePoint 2003 Resource Center
    SharePoint University
    Push the Limits of SharePoint Customization

    --Mark

  • Fifty Invites from GMail

    Today Paul pointed out that GMail has given us 50 invites to give away.

    I don't know about the rest of you, but I have had a hard time giving away the sets of six that GMail gave out in the past.

    --Mark

More Posts

Our Sponsors

This Blog

Syndication

News