Wednesday, February 23, 2011

How to add Search scopes drop-down to the Site

Here is the small artifact talks about how to add Search scopes drop down to the Site navigation bar.
  1. Click Site Actions
  2. Click Site Settings
  3. Click Search settings under Site Collection Administration
  4. Select ‘Enable Custom Scopes’ in the Site Collection Search Center
  5. Select ‘Show scopes dropdown’ under Site Collection Search dropdown Mode
  6. Click Ok.
Now, Access the site and  you should be able to see the Site scopes dropdown shown on the navigation bar of the Site.
~ Gangadhar Kotu

Thursday, December 23, 2010

Activating Office 2010 Trial (Converting to Licensed Version)

Hi,

I was facing an issue of activating the Office 2010 Trail which we have got through the Virtual machine for SharePoint from Microsoft. When I’m access any of the office applications it is telling me to activate the Office. While activating the same, I’m receiving ‘Communication error’ occurred message.

Other option I have is to activate over Telephone. But this may also required Internet access.

Interestingly, Internet is working fine while accessing from browser.

So, I searched over Internet and found the solution is as below.

Option1:

  1. Click File
  2. Click Help
  3. Change the Product Key
  4. Click Continue
  5. Click Finish

 Option2:

  1. Select activate via Phone from the Activation pop-up.
  2. Select country from the list and call the Microsoft call centre
  3. Provide the installation Id.
  4. Customer care executive would provide the confirm Id for A,B,C,D,E,F,G & H.
  5. Successful message would be displayed.

Have a good time…!!

Regards
Gangadhar Kotu

How to change the URL of the SharePoint Site

We have been thinking whether the URL of the SharePoint Site can be changeable or need to create a new web application and restore the content database on to the new web application.

You may not needed to stay hours to have the strategies planned for. We have a simple way for performing the same in SharePoint 2010. Hope this would also works for SharePoint 2007.

Objective here is to change the current site URL http://contosotest.contoso.com to http://contosodev.contoso.com.

To achieve this, we need to perform three tasks, which has been listed below.

  1. Change Alternative Access mappings
    1. Go to Central administration.
    2. Click ‘Configure Alternative Access mappings’ under Application Management
    3. Select the web application which you wish to change the URL.
    4. Change the URL to http://contosodev.contoso.com
    5. Click OK

  2. Change in IIS
    1. Go to Web site.
    2. Open up the bindings of the site (in IIS 7), change the host header details in case you are using IIS 6.0.
    3. Change the header name to contosodev.contoso.com
    4. Click OK
    5. Recycle the app pool which is being used by this site.

  3. Change in DNS entries
    1. Open the DNS manager in the Domain server.
    2. Create a new DNS entry to point to contosodev.contoso.com
    3. Click Save.

By now, you are done with all the changes. Now you can go for IIS reset on the web server. This would refresh the cache in the web server and new URL is ready to access.

Try accessing http://contosodev.contoso.com and it starts working fine.

Other things to be considered:-

  1. Ensure to change any hard coded URLs in the site (especially in the navigation)
  2. Ensure to change any URLs pointed to old URL in the content query webparts or content editor webparts. Instead if you have used relative URLs in the site, no need to change anything.

After this, ensure to browse all the areas of the site to check for any broken links are there. If not there, you can have a happy hours.

This has been working without any hassles and you can understand that how easy it is. :)

Regards Gangadhar Kotu

Wednesday, November 10, 2010

Working with Active Directory using C#

I am writing this post to all of you looking for the sample to work with Active directory services with various operations using C#. In this article, I would like to explain the below operations with Active Directory.

Operations:



  1. Create User
  2. Create Group
  3. Add User to Group
  4. Create user and add to Group
  5. Disable User
  6. Enable User
  7. Remove User from Group
  8. Remove Group
  9. Remove User


Sample Code:

using System;
using System.DirectoryServices.AccountManagement;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

namespace Aryabhatt.Samples.ActiveDirectory
{
    internal class AccountManagementService
    {
        // AD Domain Name for connecting through LDAP
        static string adDomain = ConfigurationManager.AppSettings["DomainName"];
        // User information like (OU)
        static string adContainer = ConfigurationManager.AppSettings[Constants.ConfigKeys.AD_CONTAINER];
        // Group information like (OU)
        static string adGroupContainer = ConfigurationManager.AppSettings[Constants.ConfigKeys.AD_GROUP_CONTAINER];

        // Service user name
        static string adminUser = ConfigurationManager.AppSettings[Constants.ConfigKeys.AD_SERVICE_USERNAME];
        // Service password
        static string adminPassword = ConfigurationManager.AppSettings[Constants.ConfigKeys.AD_SERVICE_PASSWORD];

        // AD LDS or AD user context
        static PrincipalContext adPrincipalContext = new PrincipalContext(
                                                                          ContextType.Domain,
                                                                          adDomain,
                                                                          adContainer,
                                                                          ContextOptions.Negotiate | ContextOptions.Sealing | ContextOptions.Signing,
                                                                          adminUser,
                                                                          adminPassword);

        /// <summary>
        /// Authenticates the user with the credentials against Active Directory
        /// </summary>
        /// <param name="userName">User name</param>
        /// <param name="password">Password</param>
        public static void ValidateUserCredentials(string userName, string password)
        {
            PrincipalContext principalContext =
                new PrincipalContext(
                    ContextType.ApplicationDirectory,
                    adDomain,
                    adContainer);
            return principalContext.ValidateCredentials(userName, password);
        }

        /// <summary>
        /// Checks if the provided userName already exists in the Active Directory. Returns True if exists.
        /// </summary>
        /// <param name="userName">User Name</param>
        /// <returns>Returns true if the user exists in AD otherwise false</returns>
        internal static bool IsUserExist(string userName)
        {
            bool userExists = true;

            try
            {
                using (UserPrincipal user = new UserPrincipal(adPrincipalContext))
                {
                    user.Name = userName;

                    // create a principal searcher for running a search operation
                    using (PrincipalSearcher principalSearcher = new PrincipalSearcher())
                    {
                        // assign the query filter property for the principal object
                        principalSearcher.QueryFilter = user;
                        // run the query
                        using (Principal result = principalSearcher.FindOne())
                        {
                            if (result == null)
                            {
                                userExists = false;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, Constants.Policies.SERVICE_BOUNDARY);
                // Not rethrowing here as AppException being thrown on the caller
            }
            return userExists;

        }

        /// <summary>
        /// Returns UserProfile object for the passed userName
        /// </summary>
        /// <param name="userName">userName</param>
        /// <returns></returns>
        private static UserPrincipal GetUserPrincipal(string userName)
        {
            UserPrincipal user = new UserPrincipal(adPrincipalContext);
            user.Name = userName;
            UserPrincipal userPrincipalResult;
            using (PrincipalSearcher principalSearcher = new PrincipalSearcher(user))
            {
                userPrincipalResult = (UserPrincipal)principalSearcher.FindOne();
            }
            user.Dispose();
            return userPrincipalResult;
        }

        /// <summary>
        /// Returns GroupPrincipal object based on the groupName passed
        /// </summary>
        /// <param name="groupName">Group Name</param>
        /// <param name="adGroupContainer">AD Group container</param>
        /// <returns></returns>
        private static GroupPrincipal GetGroupPrincipal(string groupName, string adGroupContainer)
        {
            GroupPrincipal groupPrincipalResult;


            // AD LDS or AD group context
            PrincipalContext adGroupPrincipalContext = new PrincipalContext(
                                                              ContextType.Domain,
                                                              adDomain,
                                                              adGroupContainer,
                                                              ContextOptions.Negotiate | ContextOptions.Sealing | ContextOptions.Signing,
                                                              adminUser,
                                                              adminPassword);

            GroupPrincipal group = new GroupPrincipal(adGroupPrincipalContext);
            using (group)
            {
                group.Name = groupName;

                using (PrincipalSearcher principalSearcher = new PrincipalSearcher(group))
                {
                    groupPrincipalResult = (GroupPrincipal)principalSearcher.FindOne();
                }
            }
            return groupPrincipalResult;
        }

        /// <summary>
        /// Creates an active directory user account
        /// </summary>
        /// <param name="userName">User name</param>
        /// <param name="password">Password</param>
        /// <param name="firstName">First name</param>
        /// <param name="lastName">Last name</param>
        /// <param name="emailAddress">Email address</param>
        public static void CreateUser(string userName, string password, string firstName, string lastName, string emailAddress)
        {
            if (IsUserExist(userName))
                throw new ApplicationException(Constants.ExceptionMessages.USER_EXISTS);

            try
            {
                // create a user principal, set their password and enable the account
                using (UserPrincipal user = new UserPrincipal(adPrincipalContext, userName, password, true))
                {
                    // assign some properties to the user principal
                    user.GivenName = firstName;
                    user.Surname = lastName;
                    user.EmailAddress = emailAddress;
                    if (!userName.Contains("@"))
                        user.UserPrincipalName = string.Format("{0}@{1}", userName, adDomain); // Setting up UPN value

                    user.Save();
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, Constants.Policies.SERVICE_BOUNDARY))
                    throw ex;
            }
        }

        /// <summary>
        /// Deletes the user from AD Domain
        /// </summary>
        /// <param name="userName"></param>
        public static void RemoveUser(string userName)
        {
            try
            {
                using (UserPrincipal user = GetUserPrincipal(userName))
                {
                    user.Delete();
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, Constants.Policies.SERVICE_BOUNDARY))
                    throw ex;
            }
        }

        /// <summary>
        /// Adds user to a Group
        /// </summary>
        /// <param name="userName">User name</param>
        /// <param name="groupName">Group name</param>
        public static void AddUserToGroup(string userName, string groupName, string adGroupContainer)
        {
            try
            {
                using (UserPrincipal user = GetUserPrincipal(userName))
                {
                    using (GroupPrincipal group = GetGroupPrincipal(groupName, adGroupContainer))
                    {
                        group.Members.Add(user);
                        group.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, Constants.Policies.SERVICE_BOUNDARY))
                    throw ex;
            }
        }

        /// <summary>
        /// Adds user to a Group
        /// </summary>
        /// <param name="userName">User name</param>
        /// <param name="groupName">Group name</param>
        public static void CreateUserAndAddToGroup(string userName, string password, string firstName, string lastName, string emailAddress, string groupName, string adGroupContainer)
        {
            if (IsUserExist(userName))
                throw new ApplicationException(Constants.ExceptionMessages.USER_EXISTS);

            try
            {
                // create a user principal, set their password and enable the account

                UserPrincipal user = new UserPrincipal(adPrincipalContext, userName, password, true);
                using (user)
                {
                    // assign some properties to the user principal
                    user.GivenName = firstName;
                    user.Surname = lastName;
                    user.EmailAddress = emailAddress;
                    if (!userName.Contains("@"))
                        user.UserPrincipalName = string.Format("{0}@{1}", userName, adDomain); // Setting up UPN value
                    user.Save();

                    GroupPrincipal group = GetGroupPrincipal(groupName, adGroupContainer);// GroupPrincipal.FindByIdentity(adGroupPrincipalContext, groupName);
                    using (group)
                    {
                        group.Members.Add(user);
                        group.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, Constants.Policies.SERVICE_BOUNDARY))
                    throw ex;
            }
        }

        /// <summary>
        /// Removes user from a group
        /// </summary>
        /// <param name="userName">User name</param>
        /// <param name="groupName">Group name</param>
        public static void RemoveUserFromGroup(string userName, string groupName, string adGroupContainer)
        {
            try
            {
                using (UserPrincipal user = GetUserPrincipal(userName))
                {
                    using (GroupPrincipal group = GetGroupPrincipal(groupName, adGroupContainer))
                    {
                        bool isDeleted = group.Members.Remove(user);
                        group.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, Constants.Policies.SERVICE_BOUNDARY))
                    throw ex;
            }
        }

        /// <summary>
        /// Activates the user
        /// </summary>
        /// <param name="userName">User name</param>
        public static void ActivateUser(string userName)
        {
            try
            {
                using(UserPrincipal user = GetUserPrincipal(userName))
                {
                    user.Enabled = true;
                    user.Save();
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, Constants.Policies.SERVICE_BOUNDARY))
                    throw ex;
            }
        }

        /// <summary>
        /// Disables the user from Domain
        /// </summary>
        /// <param name="userName">User name</param>
        public static void DisableUser(string userName)
        {
            try
            {
                using (UserPrincipal user = GetUserPrincipal(userName))
                {
                    user.Enabled = false;
                    user.Save();
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, Constants.Policies.SERVICE_BOUNDARY))
                    throw ex;
            }
        }

        /// <summary>
        /// Creates the group in AD
        /// </summary>
        /// <param name="groupName"></param>
        public static void CreateGroup(string groupName)
        {
            try
            {
                // create a group
                GroupPrincipal group = new GroupPrincipal(adGroupPrincipalContext, groupName);
                using (group)
                {
                    group.Save();
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, Constants.Policies.SERVICE_BOUNDARY))
                    throw ex;
            }
        }

        /// <summary>
        /// Removes the group from AD
        /// </summary>
        /// <param name="groupName"></param>
        public static void RemoveGroup(string groupName, string adGroupContainer)
        {
            try
            {
                // fetching a group
                using (GroupPrincipal group = GetGroupPrincipal(groupName, adGroupContainer))
                {
                    group.Delete();
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, Constants.Policies.SERVICE_BOUNDARY))
                    throw ex;
            }
        }
    }
}

Web.Config Entries:

<add key="DomainName" value="Dev.Arybhatt.com" />


<add key="UserName" value="ServiceAdmin" />


<add key="Password" value="P@ssw0rd1" />


<add key="UserContainer" value="OU=DevUsers,DC=Dev,DC=Arybhatt,DC=com" />


<add key="GroupContainer" value="OU=Demo,OU=Apps,DC=Dev,DC=Arybhatt,DC=com" />



Organizational Unit: An organizational unit (OU) is a subdivision within an Active Directory into which you can place users, groups, computers, and other organizational units. You can create organizational units to mirror your organization's functional or business structure. Each domain can implement its own organizational unit hierarchy. If your organization contains several domains, you can create organizational unit structures in each domain that are independent of the structures in the other domains.


User Principal : User principal object can contain only the users in the OU.
Group Principal: Group principal object can contain only the groups in the OU.
Domain Name: Domain name


Hope you got to know how simple it is. :)


Regards
Gangadhar Kotu




Thursday, August 12, 2010

Telugu Rhymes for Children

http://www.youtube.com/watch?v=SAJcdLa4fws

Wednesday, December 9, 2009

MOSS Governance considerations

Here are some of my key deployment considerations to governance & management.

  • Quota - to encourage storage management, if not manage your disk space and search relevancy
  • Usage Policies - what is ok, SharePoint Designer, Custom web parts, SQL data sources in dataviews, what types of sites do you provision, who can own a site?
  • Data/Site Retention policies - How long does data that isn't accessed or categorized or even used for a couple of years stick around?
  • Web Part/Development policies - Ownership, support, deployment?
  • Meta Data Capture & Content Types - How can you get the best data out of your users?
  • Managed Approach to deployment (top down) - What is our enterprise search story, what is our browse, site map and site directory story... What do the departments in my company use for aggregation?
  • Self Service approach to deployment (bottoms up) - how can I keep Help desk from being a bottleneck to information worker productivity
  • Montoring Plan - Is there a 24/7 plan with a MOM console? What application packs or web services verifications and synthetic transactions for verifiying uptime.
  • Global Considerations - Shared Services, WAN and end user performance levels, enteprise search considerations
  • Cost Model or Charge Back Model for recapture of IT Costs - who pays for all this?
    Solutions Deployment packaging best practices and rules to live by - How can we consistently deploy web parts, site definition changes
  • Branding - how can we consistently have a good experience for our end users and keep the sense of company ownership
  • Stakeholder and ownership - who should be involved in these decisions
  • SSP Delegation models - Who owns Search and relevancy (best bets), who owns the profiles (company directory), who owns the BDC (business data catalog) connections to our SAP, who get's safe locations for Excel published charts, spreadsheets
  • Operational & Service SLAs -
    Backup and Restore/Recovery & Business Continuance SLAs
    Uptime
    Downtime windows
    Performance SLAs
  • Communications plan - who do we communicate to, when and how often and what? Is there a Communications website where we communicate this list of info?
  • End User Education Plan - Is there an FAQ, training materials, brown bags, web sites?

I recommend going through this list, and adding more of your own, then building a governance worksheet or "Green book" that helps bring the stakeholders together.

~ Gangadhar Kotu

Features of MOSS 2010

SharePoint 2010 is the business collaboration platform for the Enterprise and the web that enables you to contact and empower people through an integrated set of rich features. SharePoint 2010 helps you cut costs with a unified infrustructure while allowing you to rapidly respond to business needs.
Features of the new SharePoint 2010
  • New User Interface including the new Ribbon - A streamlined new user interface including the Ribbon is an intuitive and contextual web user interface that makes users more effective. reduces training, provides better performance and lowers cost.
  • Web Edit - Web Edit allows users to easily customize a site, making it possible to respond more quickly than ever to changes in your dynamic business environment.
  • Silverlight Web Part - The Silverlight Web Part allows you to fully integrate Silverlight applications within your SharePoint site for a more interactive user experience.
  • Rich Theming - Combined with Web Edit, rich theming allows you to skin your SharePoint site using your favorite office client themes. Change the colors and fonts to customize just as you like it.
  • Multiple Browser Support - SharePoint 2010 will now support not only MS Internet Explorer, but now FireFox and Safari will also be fully supported.
  • Visio Services - Visio will now be fully supported. You can link diagrams in real time, with high-fidelity in a consistant matter so that everyone can stay up to dat. Even those who do not have Visio.
  • New SharePoint Designer - SharePoint Designer comes with a new User Interface with enhanced modeling capabilities and improved workflows.
  • Business Connectivity Services (The Business Data Catalog) - Business Connectivity Services (BCS) allows you to connect to Line-of-business applications, web services and databases in a user friendly way enabling users to interact and update it easily in both web and office clients.
  • SharePoint Workspace - Formally named Groove, SharePoint Workspace is a rich client for SharePoint that lets you take your SharePoint lists and libraries off-line, including the ability to update content and sync it back when you re-connect.
  • Rich Media Support - Silverlight and PowerPoint presentation capabilities are easily integrated with the new SharePoint 2010. Your information and presentations will come to life in new and dynamic ways with ShjarePoint 2010.