Search This Blog

Tuesday 22 July 2014

Compare SPUser objects in SP code

I have to compare the User value in the Assigned To Field of the List with the other User value.
Here is the exact code that will do this.

SPUser spUser = GetSPUserOne();
SPUser spPrevUser = GetSPUserTwo();

For Windows Authentication This will do

if(spUser.Sid.Equals(spPrevUser.Sid))
{
…..
}

For FBA you have to follow this

if(spUser.UserToken.CompareUser(spPrevUser.UserToken))
{
…..
}

Thursday 27 February 2014

The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered

Problem:
Recently I started facing this issue.
Whenever, I load the PowerShell ISE and Type the command to load the SharePoint PowerShell module, it starts throwing error

“The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.”
The same error comes up in the SharePoint Management Shell.

Solution:
You have someone who has the rights to run powershell add your user as SP Shell Admin.
Add-SPShellAdmin -username DOMAIN\YourUser

That's quite the nobrainer, but what happens if your user is already SPShellAdmin, shown with Get-SPShellAdmin and you get the same error popping up? In that case, something probably happened with the SQL. They restored the farm on another server and did not migrate all the access rights. Just run Add-SPShellAdmin -username DOMAIN\YourUser again and it will set the appropriate permissions.


References:

No content databases are available for this operation SharePoint 2010

An interesting issue, I faced when I am trying to restore a site collection due to accidently deletion of site collection or site become corrupted. Here is the command which I run.

PS C:\Users\mrajaram> Restore-SPSite http://***********:4126 -path “D:\***************\Site_TT_4126_Fresh.bak”

But I end up the following error


Solution:

So finally we solve the mystery. Issue is when we delete a site collection it's not deleted completely; you still have option to restore it (that's functionality available in SP 2010 with SP1 or later). It goes to Site Recycle Bin and you can restore it via following commands:

◦Get-SPDeletedSite – this command gets a list of all deleted Site Collections in your farm.
◦Restore-SPDeletedSite – this command is used to restore a deleted Site Collection within your farm
◦Remove-SPDeletedSite - this command will remove the site collection completely.

Ok. Now we run the Remove-SpDeletedSite command to remove the Site from Recycle Bin. Please wait adventure is not over yet.

You have to manually run the "Gradual Site Delete" timer job from Central Admin > Monitoring > Job Definitions and select the Web Application where you are trying to restore.




Go to Job History and check status



Wait for couple of minutes and now runs the restore command and it’s worked as per expectation.









Awesome! 

Reference:

Does not contain a static 'main' method suitable for an entry point

Recently I organized my SharePoint solutions, where I had two SharePoint projects with more than 70 supportive class files. I decided to move all supportive files inside a separate project and refer from that project. So I added new empty project on that solution and moved all class files in to that create project. But when I build the solution, I got below error

“Does not contain a static 'main' method suitable for an entry point”

Reason:
I was looking at this issue as well, and in my case the solution was too easy. I added a new empty project to the solution. The newly added project is automatically set as a console application. But since the project added an 'empty' project, no Program.cs existed in that new project. (As expected)

Solution:
All I needed to do was change the output type of the project properties to Class library

 Reference:

Access to Content Database SharePoint 2010


When I try to deploy SharePoint solution on my SharePoint Server from Visual Studio 2010, I got below error

But I was able to access the site in browser. Moreover I am the Site Collection Administrator.
Also when I try to take site backup through PowerShell, I got below error

So here the issue is we need to set privilege for this user to manage SharePoint. This can be done using PowerShell.  Refer below:

To add a user as a Shell administrator:
Add-SPShellAdmin -UserName <user name> -Database <database name>

For example, to allow user mrajaram to execute commands against the http://......:4126 site, use the following command:
Add-SPShellAdmin -UserName Domain\mrajaram
-Database (Get-SPContentDatabase -Identity http://......:4126)

Note that the Get-SPContentDatabase cmdlet and the http://......:4126 content database name are used to retrieve the SPContentDatabase object.

To remove a user from Shell Admin:
Remove-SPShellAdmin -UserName <user name> -Database <database name>

To list Shell administrators:
Get-SPShellAdmin