Wednesday, October 31, 2012

Error occurred in deployment step 'Activate Features': Cannot start service SPUserCodeV4 on computer



This error will be occured only when you are working with Sanbox solutions.

Cause for the issue :

This is because all the sandbox solution will work under SPUserCodeV4 process.

By default this process will be not active. If you want to work with Sandbox solutions you need to manually start this service or you can do the same with Scripting also.

Solution :

Here is the solution to start the service from Central administration

Go to

Central Asministartion -> System Settings -> Services on Server -> Activate the service Microsoft SharePoint Foundation Sandboxed Code Service




Error occurred in deployment step 'Activate Features': Feature with Id '' is not installed in this farm, and cannot be added to this scope



Strange error in sharepoint.

Struggled a lot to get the solution for this error finally one of my team member helped on solving this issue.

Cause for the error :

This error comes because of unused server in the multiple farm server environment.

In my case we are using multiple servers with the one of the server giving error on the central administration.

Solution :

Remove the unwanted / Error causing server from the server or fix the error

from the below section in Central administration site

Open the Central Administration -> System Settings ->Servers -> Manage Servers in this farm

Thanks !!!




http error 503 service unavailable sharepoint 2010



This is the kind of error which will frustrate you sometimes.

There are multiple reasons for this error and i am listing out some of the causes for this error and workarounds.

Please check these given steps to come over the issue.

1. Check wether your service account password changed in recent past and not upgraded properly in SP.

2. Check all the service account have the required admin permissions in the system.

3. Check the Application pool of the web application is up and the App Pool account is reflected the correct password.

4. Check all the sharepoint services are running in Services.msc

i. SharePoint 2010 Administration

ii. SharePoint 2010 Timer

5. Check weather the World Wide Web Publishing service is running.

Thank you !!!




sharepoint 2010 new web application disabled



This is because of some permissions issue in sharepoint.

Reason : Usually when you open the central administration that will be opened with your windows account.

There are chances that windows account doesn't have full permission on development environment

Solution : Open central administration as Administrator

Click on Start menu -> Right click on SharePoint 2010 Central administration Run as Administrator

Thank you !!




Tuesday, October 30, 2012

The solution cannot be removed when a job is scheduled or running



This is one of the strange issue when working with sharepoint script files.

Cause for the issue

Usually when we are working with deployment

all the script operation will be executed one after other till the completion of the deployment on the same batch file or powershell file.

This will cause this error because after performing the uninstall or remove wsp file from sharepoint it will take couple of minutes to complete the process.

Untill the operation should be paused.

Solution

This can be handled with the powershell script given below :


function WaitForJobToFinish([string]$SolutionName1)
{
    $JobName = "*solution-deployment*$SolutionName1*"
    $job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
    if ($job -eq $null)
    {
        Write-Host 'Timer job not found'
    }
    else
    {
        $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.."
    }
}




Monday, October 29, 2012

Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed



This is the one of the strange errors when working with sharepoint.

Cause for he error :

This is because sharepoint by default is provided with the minimal trust permission level.

For some operations we need trust from the security policy.

Solution :

This requires change in the Trust Level in Web.Config file of the Web app.

Go to web.config file of the web application usually this will be located in

C:\inetpub\wwwroot\wss\VirtualDirectories\[Web application directory]

and open the web.config and change the

trust level="WSS_Minimal" to trust level="WSS_Medium"

or

trust level="WSS_Minimal" to trust level="Full"

Happy coding !!


sharepoint web part display mode



Sometimes we need to check the web part mode i.e Is web part is in Edit mode or Display mode.

Based on this condition we have to do some coding..

For this SP has provided a property to check the mode of the web part.

SPContext.Current.FormContext.FormMode == SPControlMode.Edit;


Here we have four types of modes those are listed below

1. New

2. Edit

3. Display

4. Invalid


Happy coding !!!


Download wsp from central admin sharepoint

Here is the situation where we need to take the backup of the deployed wsp file in sharepoint.

For this, We can do this with the PowerShell scripting.

Following are the PowerShell script code to take the backup and restore it is local folder with .wsp externsion.

$farm = Get-SpFarm
$file = $farm.Solutions.Item("FileName.wsp").SolutionFile
$file.SaveAs("c:\FileName.wsp")


Thanks !!

Get and Set values in people picker control sharepoint



Sometimes we need to get all the people or groups information which is entered in People picker control of a sharepoint programatically.

For this we need to take the SPFIeldUserValue object to read that information.

Here is the sample code to do the same programatically.


private SPFieldUserValueCollection GetPeopleFromPickerControl(PeopleEditor people, SPWeb web)
{
  SPFieldUserValueCollection values = new SPFieldUserValueCollection();
  if (people.ResolvedEntities.Count > 0)
  {
    for (int i= 0; i< people.ResolvedEntities.Count; i++)
    {
        PickerEntity user = (PickerEntity)people.ResolvedEntities[i];
        switch ((string)user.EntityData["PrincipalType"])
        {
          case "User":
            SPUser webUser = web.EnsureUser(user.Key);
            SPFieldUserValue userValue = new SPFieldUserValue(web, webUser.ID, webUser.Name);
            values.Add(userValue);
          break;
 
          case "SharePointGroup":
            SPGroup siteGroup = web.SiteGroups[user.EntityData["AccountName"].ToString()];
            SPFieldUserValue groupValue = new SPFieldUserValue(web, siteGroup.ID, siteGroup.Name);
            values.Add(groupValue);                       
          break;
        }
      }
    }
    return values;
  }

Happy coding !!!




Monday, October 15, 2012

error occurred in deployment step 'activate features' the field with id defined in feature



This is the problem with VSSPHost4 process.

we have a solution for this is from Share point power shell

Execute the following command.

stop-process -processname vssphost4 -force

Happy coding !!!


Friday, October 12, 2012

SPWeb.RootFolder.WelcomePage not working



You cannot set the welcome page of a non publishing site with the following code :


teamWeb.RootFolder.WelcomePage = rootFolder.Name + "/" + myPage;
teamWeb.RootFolder.Update();



Don't know the exact reason why it will not work.

But it will not work as it expected to work on.

Here is the code which you can set the welcome page of a non publishing site.

You can set this only with the SPFOlder object, Then only it will work.


SPFolder folder = context.Web.RootFolder;
folder.WelcomePage = rootFolder.Name + "/" + myPage;
folder.Update();



Thank you !!