Wednesday, June 20, 2012

One or more field types are not installed properly

Scenario : Basically while multiple people working on the same server. There are chances that someone has modified something in List / Document library that is not informed to others.

In this case your sharepoint web parts will be failed in Add/Update/Delete operations. saying error "One or more field types are not installed properly".

Or if you go to the List/Document library you will get the same error.

Resolution : Go to List settings and check weather all the column names are same what you are using in code or check any changes appended to the List definition.

Thank you !!!

sharepoint designer login as different user

Here is one more article on sharepoint designer

Scenario : While we are working with sharepoint designer ( workflows, content types etc ) there are scenarios where required to login with diffarent user.

Shareoint has this feature, But lot of people not aware of this.

Solution :

1. Open sharepoint designer form start menu ( cmd -> spdesign )

2. Open a site and login with any of the user

3. Please have a look at Left hand side botton corner of the Designer windows where you will find an ICON with user image.

4. Click on that, It will lead you to change login name

Thank you.

Specific file or folder name is too long in sharepoint

Here is the issue while we upload files or create folder to sharepoint document library.

Usually get an error saying that "Specific file or folder name is too long".

Reason : Every sharepoint file name has limited number of characters, It will check for this condition before upload file to sharepoint.

Solution : Sharepoint object model has provided a beauty of way to check for the file name validity.

Here is the code :


It will return weather all the conditions are passed before upload it to sharepoint.

Thank you

powershell change service account password sharepoint

Usually, We set all the sharepoint admin accounts or service account passwords with expiry period.

After that particular period passwords will be expired. At this point of time we need to update the passwords from either Central admin or Powershell.

Here is the powershell code to update password of a sharepoint account .

$version = $host | select version
if ($ver.Version.Major -gt 1)  {$Host.Runspace.ThreadOptions = "ReuseThread"}

# 1. Adding sharepoint snap-in
Add-PsSnapin Microsoft.SharePoint.PowerShell
Set-location $home

# 2. Provide the service account name
$ServiceAccountName = Read-Host 'Service Account'

$managedAccount = Get-SPManagedAccount $ServiceAccountName

# 3. Get and confirm the serice account new password
$password = Read-Host 'Enter Password' -AsSecureString
$passwordConfirmation = Read-Host 'Confirm Password' -AsSecureString

# 4. Command to change the password
Set-SPManagedAccount -Identity $managedAccount -NewPassword $password -ConfirmPassword $passwordConfirmation -SetNewPassword

Happy sharepoint coding

http error 503. The service is unavailable Sharepoint

Issue : Service unavailable

All of a sudden your Central administration is down and showing Service unavailable. Which is very common error while you are working with sharepoint. which looks something like :

Most possible reason for this : Farm admin password expired or changed.

Resolution :

Go to IIS ( cmd -> inetmgr ) of your Web front end server.

1. click on Application pools

2. Click on Central admin Application pool ( usually it is named as "Sharepoint Central admin v4" )

3. In right corner actions Click on Advanced settings

4. Find the "Identity" section click on that and set new password.

5. Finally you will come up with your recovered Central admin.

NOTE : If you still getting the same issue try run your Configuration wizard in sharepoitn section this will fix the issue or it will log the issue in the 14 hive LOG folder.

Thank you.

Monday, June 18, 2012

powershell get help command with example

For every command in powershell we can get the example sample script using Get-Help prefix.

Below is the script to get the example for Site back up command in Sharepoint :

Get-Help BackUp-SPSite -example

Output will be looks something like :

Dynamically Retrieve a Collection URL from a Timer Job during Deployment

Here is the big issue in Sharepoint. We can deploy all the other solution in the dynamically other than timer job.

Timer job is the one sharepoint items where we cannot deploy it directly with dyncamic URL.

But microsoft has provided a good turn around for this.

Here is the good technical article where we can take dynamic URL by using feature properties from Code behind.

Click here to get the blog..

Happy coding !!!

sharepoint 2010 get list items linq without SPMetal

Hi All,
There are some situations where we need to get the data form sharepoint list items with a query.

But as we are aware linq is the best way to get the sharepoint list items in fast and efficient way. But to work with sharepoint lists we need to create entity calss with SPMetal.exe

Without using the entity class also we can get the sharepoint list items using System.Linq

Here is the sample code to get the list items from Config list using small filter option.

Here we are trying to get the Config details from Config list.

var item = web.Lists["ConfigList"].Items.OfType().FirstOrDefault(it => it["Key"].ToString() == "ConnectionString");

Friday, June 15, 2012

c# check user exists in active directory

Here is the C# code to check if user exists in Active directory or not :

using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "DomainName"))
using (UserPrincipal user = UserPrincipal.FindByIdentity(context, "LoginName"))
     bool userExists = (user != null);
     if (userExists)
       Console.WriteLine("User exists");
      Console.WriteLine("User doesn't exist");

Failed to post back after export file sharepoint

In Sharepoint if you implement functionality to generate report in new .doc or .excel or any other office file in button click.

Issue : You cannot generate report multiple times because after first click on Genrate report button your form post backs will be blocked automatically.

To overcome this issue you need to add a simple Javascript code in page load for the button. Please find the below ;

this.btnGenerateReport.OnClientClick = "_spFormOnSubmitCalled = false;_spSuppressFormOnSubmitWrapper=true;";

                            -or -

this.btnGenerateReport.OnClientClick = "javascript:History.Back()";

sharepoint get lookup value programmatically

Here is the C# code to get the Lookup field value :
SPList list = web.Lists["Tasks"];

                            SPListItem existingBranch = list.Items[0];

                            SPFieldLookupValue group = new SPFieldLookupValue(existingBranch["Food Coupons"].ToString());

                            string lookedUpItemTitle = group.LookupValue;
Here is the C# code to Set the Lookup field value :
 SPList list = web.Lists["Tasks"];

                            SPListItem newBranch = list.Items.Add();

                            newBranch["Title"] = "New lookup";

                            SPFieldLookupValue newValue = new SPFieldLookupValue(14, "Test");

                            newBranch["Sample"] = newValue;


Powershell script to wait for Job to finish

When you deploy the sharepoint solution using powershell script it will always says that the solution is not yet deployed kind of issues.

This is the place where we need to wait for the next operation to complete the previous one.

Here is the code sample for the same :

function WaitForJobToFinish([string]$SolutionName1)
    $JobName = "*solution-deployment*$SolutionName1*"
    $job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
    if ($job -eq $null) 
        Write-Host 'Timer job not found'
        $JobFullName = $job.Name
        Write-Host -NoNewLine "Waiting to finish job $JobFullName"
        while ((Get-SPTimerJob $JobFullName) -ne $null) 
            Write-Host -NoNewLine .
            Start-Sleep -Seconds 2
        Write-Host  "Finished waiting for job.."

C# code to get claims user name sharepoint 2010


IClaimsPrincipal claimsPrincipal = Page.User as IClaimsPrincipal;
                    if (claimsPrincipal != null)
                        IClaimsIdentity claimsIdentity = (IClaimsIdentity)Thread.CurrentPrincipal.Identity;
                        if (claimsIdentity != null)
                             foreach (Claim item in claimsIdentity.Claims)


Thursday, June 14, 2012

Sharepoint 2010 Claims check user name

// Comment
IClaimsPrincipal claimsPrincipal = Page.User as IClaimsPrincipal;
                    if (claimsPrincipal != null)
                        IClaimsIdentity claimsIdentity = (IClaimsIdentity)Thread.CurrentPrincipal.Identity;
                        if (claimsIdentity != null)

                            Logger.Instance.LogInfo("CreateChildControls", "User not found", false);

powershell activate feature sharepoint

  write-output $_ 
  exit 1 
# define variables for script
$webApp  =$args[0]

# 1. check to ensure Microsoft.SharePoint.PowerShell is loaded
    $snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
    if ($snapin -eq $null) 
        Write-Host "Loading SharePoint Powershell Snapin"
        Add-PSSnapin "Microsoft.SharePoint.Powershell"

# 3. Add solution to SharePoint Solution Store

        Write-Host "Getting Faeture for ID" + $featureId   

 $feature= Get-SPFeature -Identity $featureId
    $site=Get-SPSite $webApp 

     $sitefeature= $site.Features[$feature.Id]
  if($sitefeature -ne $null)
   Write-Host "Feature Already activated in this site"
   Write-Host "Disabling the Feature"
         Disable-SPFeature -Identity $feature.Id -Url $webApp  -confirm:$false -force
       Write-Host "uninstalling the Feature"
         uninstall-spfeature -identity $feature.Id  -confirm:$false -force

   Write-Host "installing the Feature"
   install-SPFeature -Path $feature.RootDirectory -confirm:$false -force
       Write-Host "Enabling the Feature"
  Enable-spfeature -Identity $feature.Id -Url $webApp -confirm:$false -force 
Write-Host "Done"

Create external list with powershell

 [string] $SiteUrl = $null

write-host "Adding Snapin"
Add-PsSnapin Microsoft.SharePoint.PowerShell
write-host "Added"

$BusinessListName = "BusinessList"
$ConfigListName = "Config"



$spweb = Get-SPWeb $SiteUrl
$ListGUID = ""
$ListUrl = "Lists/{0}"
  Write-Host "Creating and Configuring SPListDataSource"
  $ds = New-Object -TypeName Microsoft.SharePoint.SPListDataSource
  $ListCollection = $spweb.Lists
   $ds.SetProperty("LobSystemInstance", "db")
   $ds.SetProperty("EntityNamespace", "Business")
   $ds.SetProperty("Entity", "BusinessList")
   $ds.SetProperty("SpecificFinder", "GetBusinessListRead Item")
    Write-Host "Checking for list instance existence"
    $list =  $spweb.Lists[$BusinessListName];

      Write-Host "List exists - " + $BusinessListName + " - deleting the list"
      Write-Host "Creating " + $BusinessListName + " list with Data Source.."
        $ListGUID = $spweb.Lists.Add($BusinessListName, "", [String]::Format($ListUrl, $BusinessListName), $ds)
     Write-Host "List created successfully.." + 
     $list =  $spweb.Lists[$ConfigListName];

     Write-Host "List exists - Config - deleting the list"

create external list external content type

1. Open central administration and click on Manage Service application in Application management

2. Click on Business Data connectivity service link

3. Then click on Import button in Ribbon on top 4. Next screen browse the BDC model (*.bdcm ) file and click on Import. 5. Ignore the error message and click OK to complete the process. Create External list with the BCS Source: 1. Open web application -> click on Site settings -> view All Site Content -> Click on Create link 

2. In the given list templates select External List template and click on Create 3. In Create screen provide the information required like Name, Description and In Data Source Config section click on Select External Content Type icon to list all the bdcm sources shown below :

4. Then Select RadBusinessList in the pop up and click on OK



Done, Finally External List looks like this :