الأحد، 26 فبراير، 2012

SharePoint 2010 Custom Welcome Control

To be written letter...

الجمعة، 24 فبراير، 2012

SharePoint 2010 >> Possible ways to get logged in User Name & Handling Changes in FBA Users' Names if Membership Provider Name Changed

بسم الله الرحمن الرحيم 

You may needed, in many cases, to have the logged in user name in SharePoint 2010. And you may found all old FBA (Form Based Authentication) user names changed suddenly after you change the Membership Provider name. For this or that, you need to read this article.
To get the logged in user name you have the following methods available in SharePoint 2010 Web Part User Control:
  • this.Page.User.Identity.Name
  • HttpContext.Current.User.Identity.Name
  • SPContext.Current.Web.CurrentUser.LoginName
  • SPContext.Current.Web.CurrentUser.Name
Actually, there is also: "System.Web.Security.Membership.GetUser().UserName". But it gave me Exception with message: [Method or operation is not implemented]
However, I called each of the previous four properties for both windows (SharePoint System Account) and forms authentication. They returned with the following:
For "System Account" user with user called "user _name" and domain named "domain_name":
Property
Returned Value
Page.User.Identity.Name or
HttpContext.Current.User.Identity.Name
0#.w|domain_name\user_name
SPContext.Current.Web.CurrentUser.LoginName
SHAREPOINT\system
SPContext.Current.Web.CurrentUser.Name
System Account
For a Form Based Authenticated User called "fba_user" and Membership Provider called "membership_provider":
Property
Returned Value
Page.User.Identity.Name or
HttpContext.Current.User.Identity.Name
0#.f|membership_provider|fba_user
SPContext.Current.Web.CurrentUser.LoginName
0#.f|membership_provider|fba_user
SPContext.Current.Web.CurrentUser.Name
fba_user

But, the value for the last one (SPContext.Current.Web.CurrentUser.Name) could be changed to the format: 0#.f|membership_provider|fba_user, instantly, if you changed the membership provider named! This means that the user name will be ugly. Moreover, this ugly name will be shown in the ribbon!
However, get relaxed you can easily fix the name at your code; you can just extract the username from the long text. This can be easily done by:

public string GetFlatUserName()
{
    //First, be sure that the user is not anonymous user:
    if (SPContext.Current == null || SPContext.Current.Web.CurrentUser == null)
        return "Anonymous";
    //Second, parse it:
    else
    {
        string flatUserName = this.Page.User.Identity.Name;
        if (flatUserName.Contains("\\"))
        {
            flatUserName = flatUserName.Substring(flatUserName.IndexOf("\\") + 1);
        }
        else if (flatUserName.Contains("|"))
        {
            flatUserName = flatUserName.Substring(flatUserName.IndexOf("|") + 1);
        }
        return flatUserName;
    }
}
For more on fixing the ugly name shown in the Ribbon check: SharePoint 2010 Custom Welcome Control)

Kindly support me by giving some good feedback, adding some useful comments, share it at Facebook and/or make a +1 for this article at Google from the bottom of the page.
________________________________
(Muhammad Altabba)محمد الطباع 
SharePoint Developer with Project Management and Team Leadership Activities
.


الثلاثاء، 14 فبراير، 2012

Configuring Windows Users for SharePoint 2010 Administration and Development

بسم الله الرحمن الرحيم
Configure a users to do Administration and Development on a Web Application
You will need to do two things:
I)             Give user Full Control at Web Application Level Permission Policies
  1. Verify that you have the following administrative credentials:
·         You must be a member of the Farm Administrators group on the computer that is running the SharePoint Central Administration Web site.
  1. On the Central Administration Web site, in the Application Management section, click Manage web applications.
  2. Click to highlight the line for the Web application whose permission policy you want to manage.
  3. In the Policy group of the ribbon, click User Policy.
  4. In the Policy for Web Application dialog box, select the check box next to the user or group that you want to manage, and then click Add Users.
  5. In the Add Users dialog box, in the Zone list, click the zone to which you want the permission policy to apply.
  6. In the Choose Users section, type the user names, group names, or e-mail addresses that you want to add to the permission policy. You can also click the applicable icon to check a name or browse for names.
  7. In the Choose Permissions section, select the permissions that you want the users to have. In case that you want the user to be able to do everything including deployment, you choose “Full Control”.
  8. In the Choose System Settings section, check Account operates as System if you want to specify whether a user account should be displayed as SHAREPOINT\System instead of the actual accounts that perform specific tasks within the SharePoint environment.
  9. Click Finish.
II)            Provide the User with the ability to run the needed tools as Administrator:
After login to the server, the user must be able to run applications and tools, provided by Microsoft, like: SharePoint PowerShell, Visual Studio, Command Prompt, SPMetal…
And he must be able to install and run, as an administrator, programs and tools like: CAML Query Builder.
You may manage to do this by adding the user to the Local Administrators group; Or, any other good way.
However, the previous configuring will not give the user the ability to do administration control on the farm level. If you in need for that check the next section.
Plan for Farm Administration User:
To be able to act as an administrator on all SharePoint web applications and be able to configure thins like Quota and Service Applications (such as Search and Profile Synchronization), a user has to be a Farm Administrator. For that you have to do many things. For more information about managing Farm Administrators, kindly check this article: Creating Additional SharePoint 2010 Farm Administrators.


________________________________
محمد الطباع (Muhammad Altabba)
SharePoint Developer with Project Management and Team Leadership Activities.

الاثنين، 6 فبراير، 2012

Removing selection dotted borders around links that shows up on focus in Internet Explorer!

بسم الله الرحمن الرحيم
Dear all,
If you want to remove the selection dotted borders, that is made by Internet Explorer on links, that shows up when there is a focus on a link; when for example the user clicks on that link. You can add the following to your page. Absolutely, if you are using ASP.net, you will put this in the master page:
<script type="text/javascript" src=" http://code.jquery.com/jquery-1.7.1.js"></script>

<script language="javascript" type="text/javascript">
    jQuery(document).ready(function () {
        jQuery('a').focus(function () { jQuery(this).blur(); });
    });
</script>
The code will execute when the page finish loading, and will be applied on all ‘a’ tags. And, it will remove the focus on that tag immediately after focusing on it.
For more information about ready() function check: Tutorials: Introducing $(document).ready() at url: (http://docs.jquery.com/Tutorials:Introducing_$(document).ready()). And for more information about focus() function: http://api.jquery.com/focus/. Also, you can check http://api.jquery.com/blur/ for information about blur().
However, if you need to still apply this after Ajax calls! You will need to do as the following. In case, you are using ASP.Net and C#:
//Remove focus on links:
string scriptblock = "jQuery('a').focus(function(){jQuery(this).blur();});";
ScriptManager.RegisterClientScriptBlock(this.upLibraryEvents,
    typeof(UpdatePanel),
    "RemoveFocus", scriptblock, true);

You may ask: Why? Why caring about this? This is not even noticeable from normal user! And even if, the user noticed it, it does no harm!
The answer is that it is just to be used if the one, who is in somehow, responsible of quality assurance of your sites, tends to check the site not as a normal user!
Thanks to Alaa' Alkateeb.
Best Wishes,

Kindly support me by giving some good feedback, adding some useful comments, share it at Facebook and/or make a +1 for the article at Google from the bottom of the page.

________________________________
محمد الطباع (Muhammad Altabba)
SharePoint Developer with Project Management and Team Leadership Activities.