Thursday, June 30, 2011

Role Based Content in Sharepoint Content Editor Web Part

The requirement here is: My client wants to show different contents in the content editor web part to Anonymous users and authorized users. To handle these kind of security trimming, we usually use "Security Trimming" in the master page.

But here, the end user doesn't want to place the content in master page, as it will repeat on every page. The requirement is targeted on ONLY one page. So, We need role based content inside SharePoint content editor web part.

Alright, Here is the solution for the issue:

Insert the below code to Master page: (You can insert just below <form runat="server" onsubmit="return _spFormOnSubmitWrapper();"> )

<script>
  var UserHasPermissions=false;
</script>

<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="ManageWeb">

  <script>
    UserHasPermissions=true;
  </script>

</SharePoint:SPSecurityTrimmedControl>

Save & Publish the master page.

Now, In the content editor webpart on the target page,  place the below logic code.

<script>
if (UserHasPermissions)
{
  // Place the content for Logged-in user 

else
{
 //Place the content for anonymous user 
}
</script>

That's it, we are done.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, June 28, 2011

How to Create Slipstream Installation of SharePoint 2010 cumulative updates, Service Packs

By the way, what is Slipstream Installation?
Well, If you want to combine your service pack's with SharePoint installers, so that you don't need to apply service pack after the installation (Service packs will be combined with installers and you will get latest build on one time installation!) you can use SlipStreaming.

OK, How to create Slipstream of SharePoint installer? simple. Download and extract the service packs, place them under "Updates" folder of SharePoint installer media!

Here is the detailed instructions on creating SharePoint slipstream installation:
If you are running with SharePoint foundation, you can just download service packs/patches/cumulative updates. If you have SharePoint Server, You must download the service packs for both SharePoint Foundation and SharePoint Server from the URLs: http://technet.microsoft.com/en-us/sharepoint/ff800847/

Update: As a result of new packaging, This has been changed as of August 31, 2011! Its no longer necessary to install SharePoint foundation updates first and then Install SharePoint Server update!!

Step 1: Download SharePoint 2010 SP1:
http://www.microsoft.com/download/en/details.aspx?id=26640
http://www.microsoft.com/download/en/details.aspx?id=26623

Step 2: Copy the whole SharePoint 2010 installation DVD to local disk, lets say: D:\SP2010\, and Extract the service packs to the update folder (in my case it is D:\SP2010\Updates)

sharepointfoundation2010sp1-kb2460058-x64-fullfile-en-us.exe /extract:D:\SP2010\Updates
sharepoint 2010 slipstream
Wait for the extraction to complete
sharepoint 2010 slipstream service pack 1
Step 3: Copy the extracted files into the Updates Folder
sharepoint slipstream updates
Step 4: Now, Run Installer (Setup.exe) from D:\SP2010. All updates from "Updates"folder will be automatically installed!

Same procedure applies to slipstream SharePoint language packs, CUs and other service packs like SP1, SP2,etc. Here is my another post on creating slipstream version of MOSS 2007: Slipstream SharePoint 2007 to Install in Windows 2008 R2

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, June 24, 2011

Find All Incoming E-Mail Enabled Lists and Libraries in SharePoint

During Migration, Needed a List of location where Incoming E-Mail is enabled. So Here is the script which gives that!

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$SPWebApp = Get-SPWebApplication "http://sharepoint.com"
 
<# If it is MOSS 2007, You can use:
$SPWebApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup(http://sharepoint.com)
 To get SPWebApplication Object
#>
 
#create a CSV file
"E-Mail,List,Site" > "EMail-Enabled.txt" #Write the Headers in to a text file
 
foreach ($SPsite in $SPwebApp.Sites)  # get the collection of site collections
{ 
    foreach($SPweb in $SPsite.AllWebs)  # get the collection of sub sites
        {
            foreach ($SPList in $SPweb.Lists)
                {
                    if ( ($splist.CanReceiveEmail) -and ($SPlist.EmailAlias) )
                        {
                            # WRITE-HOST "E-Mail -" $SPList.EmailAlias "is configured for the list "$SPlist.Title "in "$SPweb.Url
                            $SPList.EmailAlias + "," + $SPlist.Title +"," + $SPweb.Url >> EMail-Enabled.txt  #append the data
                        }
                }
        }
}

Don't have PowerShell? Want to achieve the same using C# code: (console application).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.IO;

namespace GetEnvironmentDetails
{
    class FindIncomingEMailEnabled
    {
        static void Main(string[] args)
        {
            string site;

            try
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("Enter the Web Application URL:");
                    site = Console.ReadLine();
                }
                else
                {
                    site = args[0];
                }

                //objects for the CSV file generation
                StreamWriter SW;
                SW = File.AppendText("c:\\IncomingEmails.csv");

                //Write the CSV Header
                SW.WriteLine("Site Name, List Name, List URL, E-Mail");
                SPSite tmpRoot = new SPSite(site);
                SPSiteCollection tmpRootColl = tmpRoot.WebApplication.Sites;

                //Enumerate through each site collection
                foreach (SPSite tmpSite in tmpRootColl)
                {
                   //Enumerate through each sub-site
                    foreach (SPWeb tmpWeb in tmpSite.AllWebs)
                    {
                        //Enumerate through each List
                        foreach (SPList tmpList in tmpWeb.Lists)
                        {
                            //Check Incoming Email is enabled
                            if(tmpList.CanReceiveEmail & (!string.IsNullOrEmpty(tmpList.EmailAlias)))
                            {
                            //Log the details to a file
                            SW.WriteLine(tmpWeb.Title.Replace(",", " ") + "," + tmpList.Title.Replace(",", " ") + "," + tmpSite.Url + tmpList.DefaultViewUrl + "," + tmpList.EmailAlias.ToString());
                            }
                        }                 
                    }
                }
                                                
                //Dispose of the bjects
                SW.Close();
            }

            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry("Get Incoming Emails Detail", ex.Message);
            } 
        }
    }
}

Alternatively, You can write & run the below SQL Query on each content database, However I wont recommend it (Even with No Lock!)

SELECT Webs.FullUrl, AllLists.tp_Title, AllLists.tp_EmailAlias
FROM AllLists With (NOLOCK)
Inner join webs With (NOLOCK) on AllLists.tp_WebID = Webs.Id
where AllLists.tp_EmailAlias is not null


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, June 20, 2011

Distribute and Load Balance SharePoint Central Administration site

Its a best practice to Distribute and Load balance the SharePoint Central Administration site at least to two servers in the Farm. This will be extremely helpful in the event of one server failure and of course Microsoft supports this 100%.

How do I distribute Central Administration to 2 servers?
Lets say we have two servers: G1SPS01 and G1SPS02. Say G1SPS01 hosts Central Admin and G1SPS02 doesn't currently.

To add SharePoint Central Administration role to the Server G1SPS02, run SharePoint Configuration Wizard on the Server G1SPS02 and at the "Completing the SharePoint Products and Technologies Configuration Wizard" step, click on Advanced Settings, Select "Use this machine to host the website" to add SharePoint Central Administration role and click OK. Click Next to start the configuration wizard

After the configuration wizard completes successfully, you will have additional server providing Central Administration role.

How do I verify that my new server has Central Admin role?
In SharePoint Central Administration site, Under the operations tab, open servers in the Farm link, Now you should see Central administration is listed in both servers.
load balanced sharepoint central administration

Do these 2 Fixes aftermath:

Once we provision Central Admin site in new server, We have to do these two fixes because:
  1. Launching the "Central Administration" in G1SPS02 from Start menu shortcut open the Central Administration of G1SPS01. This is because the shortcut runs PSconfigUI.exe and reads a Registry key to determine Central Administration URL.
 

            2. Hitting https://G1SPS02:2007/ from G1SPS02 launches the Central Admin, But further navigating to other pages redirects to the another server https://G1SPS01:2007/. So do these two fixes.

Fix 1: Change the Alternate Access Mapping
  • Open “SharePoint 2010 Central Administration” Select “Configure alternate access mappings” under Operations tab.
  • Select “Change Alternate Access Mapping Collection” and then Select “Central Administration”
  • Click “Edit Public URLs”
  • Make the changes as The Default is “https://G1SPS02:2007" and for the Intranet “https://G1SPS01:2007”.load balance central administration sharepoint 2010

Fix 2: Change the Central Administration Shortcut in Registry:
Central Admin shortcut in Start menu reads the registry string: CentralAdministrationURL under HKLM\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\WSS


Change it in your new server G1SPS02 in that server.
Distribute and Load Balance SharePoint Central Administration site

Now, We have distributed the Central Administration site. You can setup a Load balancer to really load balance it. You can edit the Host headers in IIS. Also you can change the existing Central Admin ports by: stsadm –o setadminport –port 2010

Hmm, What is you failed to do this earlier? Don't panic. Still you can manage by provisioning SharePoint central Admin site:  psconfig -cmd adminvs -provision -port 2012 -windowsauthprovider "onlyusentlm"

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, June 15, 2011

Branding SharePoint 2007 Top Navigaion Bar with Images

Want to give some stylish look and feel for the Top link Bar? like the below one:


MOSS 2007 Top link bar uses the following CSS Classes from Core.CSS:
1.  .ms-topnav
2.  .ms-topnav a
3.  .ms-topnavselected
4.  .ms-topnavselected a

So, Customize the above CSS classes. Either we can place them in our own

Here is what I've done:

.ms-topnav{
border:none;
background:url("/_layouts/images/left_inactive.gif") top left no-repeat transparent!important;
font-family:Tahoma;
font-size:8pt;
color:#3764a0;
height:42px;
}

.ms-topnav a{
display:block;
white-space:nowrap;
padding:23px 12px 0px 12px;
height:42px;
color:#013d79;
background:url("/_layouts/images/right_inactive.gif") top right no-repeat transparent!important;
}

.ms-topnavselected{
color:#013d78;
background:url("/_layouts/images/left_active.gif") top left no-repeat transparent!important;
border:none;
font-weight:bold;
}

.ms-topnavselected a{
padding-top:17px;
color:#ffffff;
background:url("/_layouts/images/right_active.gif") top right no-repeat transparent!important;
}

And here are the Images:





Related Post:
Branding SharePoint 2010 Top Navigation Dropdown Menu Bar
http://chrisstahl.wordpress.com/2010/11/04/customizing-sharepoint-2010-global-navigation-with-css-and-jquery-2/


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, June 14, 2011

Excellent Online Tools to Build & Test Regular Expressions

Often I'm forgetting syntax with regular expressions and it leads to trouble! Lately I find these online tools which helped me to build better regular expressions in my coding (Yes, I do code rarely!)

1. http://gskinner.com/RegExr/   - Online Regular Expression builder with brief help text on each regular expression characters. http://gskinner.com/RegExr/desktop/ - Desktop version of above.
Online Tools for Regular Expressions

2. http://txt2re.com - Online regular expression builder, with Source code builder for Javascript, C#, Java, etc.
3. Another nice online utility: http://regexhero.net/tester/


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, June 12, 2011

Configure People Picker for Multi-Domains(or Cross Domains), Forests Environments

By default, the people picker will issue queries to all two-way trusted domains and two-way trusted forests to search people & groups. It uses the application pool account to search the target domains and forests.
Configure People Picker for Multi-Domains, Multi Forest

If the application pool account does not have permission to the target domains or forests, or if you want to use different account to search the target domains or forests, you can use the below steps:

If the AD domain has a 1-way trust, then you need to specify a username and password, execute the following commands on every server in the farm:
stsadm –o setapppassword –password MyPassword
ensure you use the same password for each server you execute this command on!

On every WFE in the farm execute the following command to instruct the people-picker to use the corret AD domain:
 stsadm -o setproperty -pn peoplepicker-searchadforests -pv domain:YourDomain.com,domain\user,password –url relevant web application
you need to run this for each web application, if you do not run this on the WFE you will see a “callback error” in the people-picker

Note: you can specify mulitple domains to lookup as well, just encapsulate the domain names in quotation marks and seperate them with a semi-colon (-pv "YourDomain1.com;YourDomain2.com”,domain\username,password)

If the AD domain has a 2-way trust you do not need to run the stsadm –o setapppassword command, just execute this one:
stsadm -o setproperty -pn peoplepicker-searchadforests -pv domain:YourDomain.com,domain\user,password –url relevant web application
you need to run this for each web application, if you do not run this on the WFE you will see a “callback error” in the people-picker

If you need to reset the people-picker back to normal, just execute this command:
 stsadm -o setproperty -pn peoplepicker-searchadforests –pv (don’t specify anything here) –url relevant web application
you need to run this for each web application, if you do not run this on the WFE you will see a “callback error” in the people-picker

In case of Cross forests:
stsadm.exe -o setproperty -url <URL> -pn "peoplepicker-searchadforests" -pv "forest:forest.corporate.com (forest:DnsName) ;domain:na.corporate.com", LoginName, P@ssword
Don't forget to do the IISReset!

More Info:
MOSS 2007: http://technet.microsoft.com/en-us/library/cc263318%28office.12%29.aspx
SharePoint 2010: http://technet.microsoft.com/en-us/library/gg602066.aspx#section4
http://technet.microsoft.com/en-us/library/gg602075.aspx
http://blogs.msdn.com/b/joelo/archive/2007/01/18/multi-forest-cross-forest-people-picker-peoplepicker-searchadcustomquery.aspx


Limit the People Picker in SharePoint 2010 to a Specific OU or Domain
Say, There are two Site Collections: Sales and Legal. Active Directory is setup to store Sales department users in the Sales Organizational Unit and Legal department users in the Legal Organizational Unit. The requirement is to prevent Sales users from adding site/library/item permissions for Legal users, and vice versa.

So here is the solution:
Run the following PowerShell commands
Set-SPSite -Identity http://portal/sites/sales -UserAccountDirectoryPath "OU=sales,OU=SharePoint,DC=MYCOMPANY,DC=com"Set-SPSite -Identity http://portal.contoso.com/sites/legal -UserAccountDirectoryPath "OU=Legal,OU=SharePoint,DC=MYCOMPANY,DC=com"

Here is a related post: http://sharepointserver-2007.blogspot.com/2008/10/limiting-sharepoint-people-picker.html


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, June 7, 2011

SharePoint Column/Field Display Name vs Internal Name

In SharePoint, When we create a column on a site/list/document, It has two names:
  1.     Internal Name - which is the name given to it when it was created and it wont be changing.
  2.     Display Name - You can change the display name as many times as you want.
Best example to understand internal name is "Modified By" field which is having internal name "Editor". When you edit the column name and change it to something totally different, the internal name doesn't change. But why should we care?

Well, Because:
  • When writing code that interacts with SharePoint's object model, some methods requires the field's Internal Name, and others the Display Name.
  • When working with Data Views, some third party controls, and custom Web parts - we must use the internal name
So, how to Identify the Internal SharePoint Column Name?
Important: Open your SharePoint site in Firefox/Google Chrome (IE does different encoding!)
  1. Sort the List / Document Library column by clicking it, and check in URL for SortField parameter value.
  2. Go to List / Document Library Settings, click on the name of the column to modify it and in URL find the last parameter value (Field)
  3. SharePoint Column Display Name vs Internal Name
What is the Best Practice in creating site/list/document columns
Name them without any special characters or spaces.  After the column is created, rename it with the special characters or spaces. This way the internal name will be "clean". E.g.
  • Display Name: My Column Name. Internal Name: MyColumnName
Here is the reference Table for SharePoint Internal naming characters

CharacterInternal Hex CodeCharacterInternal Hex Code
~_x007e_:_x003a_
!_x0021__x0022_
@_x0040_|_x007c_
#_x0023_;_x003b_
$_x0024__x0027_
%_x0025_\_x005c_
^_x005e_< _x003c_
&_x0026_> _x003e_
*_x002a_?_x003f_
(_x0028_,_x002c_
)_x0029_._x002e_
__/_x002f_
+_x002b_`_x0060_
-_x002d__x0020_
=_x003d_
{_x007b_
}_x007d_

SharePoint internal name length: Internal names are trimmed with 32 character length.

Change SharePoint internal column name: Is it possible to change Internal name of the column? Unfortunately, NO! without recreating the column, you can't change the internal name of the field.

Get Field Internal Name Programmatically: 
To get SharePoint internal column name using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$Web= Get-SPWeb "http://sharepoint.crescent.com"
$list= $web.Lists.TryGetList("Risk Metrics")

#Get "Program Name" Field
$field = $list.fields | where {$_.Title -eq "Program Name"}

#Get Field Internal Name 
write-host $field.InternalName

Find Internal Names of All Fields using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Get Internal Name of the columns
$web = Get-SPWeb "http://portal.crescent.com/" 

#Get the list
$list = $web.GetListFromURL("Lists/ChangeRequest/AllItems.aspx")

#Get display name and internal name of each field
foreach ($column in $list.Fields){
    $column | Select-Object -Property InternalName,Title
} 


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, June 6, 2011

Show Login for Anonymous user and Logout for Authenticated users

Here is my requirement: I want to Show Custom Log-in button for Anonymous user, and once logged in I want to show the Log-out for Authenticated users.

Here is the implementation part.

1. create your own Log-in and Log-out button images, place them under: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\IMAGES

Important: Do not forget to set the images security property, otherwise you will get Log-prompt even though you enabled anonymous access. Here is the screen shot.



2. Edit the individual page if you want for ONLY one page / or Master page if you want these buttons to appear in every page

3. Place the below code:
<div id="RegistrationLink"><img src="_layouts/images/login.gif" /></div>
<SharePoint:SPSecurityTrimmedControl ID=SPSecurityTrimmedControl1  PermissionsString=BrowseDirectories runat=server>
<script type="text/javascript" language="javascript">
document.getElementById("RegistrationLink").style.display = "none";
</script>
<img src="_layouts/images/logout.gif" />
</SharePoint:SPSecurityTrimmedControl>
4. you are done! Here are the result screen shots.

Before Login:


After Login:



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, June 2, 2011

SharePoint Site is Read-only to Everyone: Including Farm Administrator, Site Collection Owner

Ever faced this odd problem? where SharePoint Site is read-only to every one.. Including Farm Administrator, Site Collection Administrator.. They would only have basic permissions & various OK buttons were greyed out.

This is because, Sharepoint site collection/database into Read Only mode! To unlock the Sharepoint site either use Central Admin Site quota page or stsadm.

Central Administration
Go to Application Management >> SharePoint Site Management >> Site collection quotas and locks >> Select the correct web application and site collection >> Set the lock status of the collection (it most likely will be set to "Read-only", and you'll need to move that radio button to "Not locked").

SharePoint Site is Read-Only

Stsadm
stsadm -o -setsitelock -url http://teamsites.Crescent.com/sites/abc -lock None

That's all!

Tail:  This may happen when the content Database is in read-only mode or in Single user Mode!

By the way, If you want to set a Site collection to Read-only you can use the above option. Just set the lock status to  "Read-only".
Want to Set the Entire SharePoint Web Application, Farm to Read-only? Refer my another article: Set SharePoint Web Application or Farm to Read Only Mode


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


You might also like:

Related Posts Plugin for WordPress, Blogger...