Monday, 8 October 2012

Error Type: Error occurred in deployment step 'Add Solution': Cannot start service SPUserCodeV4 on computer ''.



While deploying the solution using visual studio 2010 , got the following error 'Error occurred in deployment step 'Add Solution': Cannot start service SPUserCodeV4 on computer 'UKREDDY'.'

There are two reason for the error. Those are,

1. SharePoint 2010 User Code Host service not started and
2. Microsoft SharePoint Foundation Sandboxed Code Service not started.

Now, we need to solve these two reasons

Step 1:

Open Services.msc in run command and check whether service is started or not  or Disabled?



if not started then start the service then right click on service and select 'Start'.

If The service is disabled then right click on service and select properties.



Now, change service startup type to automatic and click on 'OK'.



Now, right click on service then select Start.
it will takes few seconds time to start the service.




Step 2:

Check Microsoft SharePoint Foundation Sandboxed Code service is started or not.

You can do the following steps to resolve it.

a. Go to Central Administration

b. Open "System Settings"

c. Open "Manage services on server".



d. Locate the service "Microsoft SharePoint Foundation Sandboxed Code service"



e. Start the service  "Microsoft SharePoint Foundation Sandboxed Code service".



Close your application and reopen and now deploy sandbox solution, will deploy successfully. 


Thursday, 4 October 2012

Trick and Tip: How to get list of site collections details in each content databasse in SharePoint using PowerShell


Here another powershell cmdlet to know list of site collections details in each content database using powershell cmdlets

for this i used the following powershell cmdlet

Get-SPContentDatabase | %{Write-Output "ContentDB is - $($_.Name)"{sites are}; foreach($site in $_.sites) {write-Output $site.url}{"-----"}}


and output will look like this


Trick and Tip: How to know associated content databases to each web application in SharePoint using powershell


Here one small cmdlet to know content databases details for each web application in my SharePoint.
For this am going to use the following powershell cmdlet
"Get-SPWebApplication | %{Write-Output "`n- $($_.url)"; foreach($cd in $_.contentdatabases){Write-Output $cd.name}} "
and OutPut is like this

How to create site collection in a Specified or default Content Database using PowerShell


In previous post, created web application using powershell.


Now , creating new site collection using powershell.


Method 1:

Creating new site collection in default content database of the web application.

New-SPSite -Url http://ukreddy:8998/sites/newsitecol2 -OwnerAlias "UKREDDYSYKAM\Administrator" -Name "newsitecollection" -Description "Sitecoll Description" -Template $template



Method 2:


We can create new site collection in a specific content database.

here,Creating new content database and then will create new site collection in newly created content database

a. New-SPContentDatabase -Name "WSS_Content_Developemnt" -WebApplication http://ukreddy:8998

b.

This can not be done from within Central Administration web site.

New-SPSite -Url http://ukreddy:8998/sites/newsitecol2 -OwnerAlias "UKREDDYSYKAM\Administrator" -ContentDatabase WSS_Content_Developemnt  -Name "newsitecollection" -Description "Sitecoll Description" -Template $template

Method 3:

Create new site collection in a specific content database.

a. New-SPSite -Url http://ukreddy:8998/sites/newsitecol2 -OwnerAlias "UKREDDYSYKAM\Administrator" -ContentDatabase WSS_Content_8998 -Name "newsitecollection" -Description "Sitecoll Description" -Template $template

How to create Web Application in SharePoint using poweshell


In previous post , created web application using Server Object Model.

Now , try to create new web application using PowerShell Management.


Method 1:

This method using in-line command.

New-SPWebApplication -Name "UKREDDYSITE" -Port 8888 -URL "http://ukreddy" -ApplicationPool "SharePoint8888" -ApplicationPoolAccount (Get-SPManagedAccount "UKREDDYSYKAM\Administrator") -DatabaseName "WSS_Content_8888" -DatabaseServer "UKREDDY" -AllowAnonymousAccess: $false -AuthenticationMethod "NTLM" -SecureSocketsLayer:$false

Method 2:

This method using Script file.

Copy the following code snippet and paste it in notepad then save it as "<filename>.PS1" 

Then execute the PS1 file in powershell.



$sp_webapp_name = read-host -prompt ‘Web application name:’
$sp_webapp_port = read-host -prompt ‘Web application port:’
$sp_webapp_Url=read-host-prompt 'Web application URL'
$sp_webapp_url =  $sp_webapp_Url
$sp_webapp_apppool = read-host -prompt ‘Web application pool name:’
$sp_webapp_apppoolaccount = read-host -prompt ‘Web application pool account:’
$sp_webapp_databasename = read-host -prompt ‘Web application pool database name:’
$sp_webapp_databaseserver = read-host -prompt ‘Web application database server name:’

#Create a new Web Application
New-SPWebApplication -name $sp_webapp_name -Port $sp_webapp_port  -URL $sp_webapp_url -ApplicationPool $sp_webapp_apppool -ApplicationPoolAccount $sp_webapp_apppoolaccount -DatabaseName $sp_webapp_databasename -DatabaseServer $sp_webapp_databaseserver



Programmatically how to create site collection in SharePoint 2010


In previous post we have seen how to create web application using server object model.


Now here the code snippet to create new site collection using Server Object Model.


Method 1:


in this method , first, once again creating new web application then creating root site collection in that web application. 


try
{
int port = Convert.ToInt32(txtPortNo.Text);

string UserName = txtUN.Text;
string DBName = txtDBName.Text;
string ServerName = txtServerName.Text;
string SiteCollectionTitle = txtSiteCollectionTitle.Text;              
string SiteCollectionDesc = txtSiteColDesc.Text;
string SiteColOwner = txtSiteColOwner.Text;
string SiteColOwnerEmail = txtEmailAddress.Text;
bool isAvail = CheckPortUsage(port);
if (isAvail)
{
SPWebApplicationBuilder builder = new SPWebApplicationBuilder(SPFarm.Local);

SPWebApplication newApplication;
builder.Port = port;
builder.ApplicationPoolId =
"SharePoint - " + port.ToString();

builder.IdentityType = IdentityType.SpecificUser;
SPFarmManagedAccountCollection manaccountcollection = new SPFarmManagedAccountCollection(SPFarm.Local);
SPManagedAccount maccount = manaccountcollection.FindOrCreateAccount(@UserName);
builder.ManagedAccount = maccount; //use the SPManagedAccount to receive the username and password automatically
builder.RootDirectory = new System.IO.DirectoryInfo("C:\\Inetpub\\wwwroot\\wss\\VirtualDirectories\\" + port.ToString());
builder.CreateNewDatabase = true;
builder.DatabaseName = DBName;
builder.DatabaseServer = ServerName;
builder.UseNTLMExclusively =
true;

newApplication = builder.Create(); // Create new web application
newApplication.Name = "SharePoint-" + port;
newApplication.Provision();
SPSite mySiteCollection = newApplication.Sites.Add("/", SiteCollectionTitle, SiteCollectionDesc, 1033, "STS#0", @UserName, SiteColOwner, SiteColOwnerEmail);

mySiteCollection.Close();
MessageBox.Show("Web Application and site collection Created Successfully");

}
else

{
MessageBox.Show("Port Not available");

}
}
catch (Exception ex)

{
label1.Text = ex.Message;
}



public static bool CheckPortUsage(int port)

{

try

{

new TcpClient(new IPEndPoint(IPAddress.Any, port)).Close();

return true;

}

catch

{

return false;

}

}



Method 2:


in this method  we are trying to create a site collection(if u want to create root site collection replace "sites/sitecol3" with "/") in already existing web application.


SPSite site = null;

try
{

SPWebApplication webApplication = null;

webApplication = SPWebApplication.Lookup(new Uri("http://ukreddy:8998"));
site = webApplication.Sites.Add("sites/sitecol3", "anothersitecollection", "sitecolection", 1033, "STS#0", "UKREDDYSYKAM\\administrator", "UKREDDYSYKAM\\administrator", "s.urkeddy@gmail.com");
}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

Pls let me know your queries/suggestions ...

Friday, 21 September 2012

Error Type: Microsoft SharePoint is not supported with version 4.0.30319.17626 of the Microsoft .Net Runtime (Powershell).


After installing SharePoint 2010 on Windows Server 2008 R2 am getting the following while executing powershell cmdlet i.e
 
"Microsoft SharePoint is not supported with version 4.0.30319.17626 of the Microsoft .Net Runtime"



Then i checked version of the powershell using cmdlet "$PSVersionTable"

 
 
In order to make use of the powershell cmdlets, need to switch powershell version back to version 2.
 
Note: This will not uninstall version 3, it will launch a new instance that use version 2.
 
Powershell cmdlet to switch powershell version 2 is "powershell -version 2"
 
 
Then run Add-PSSnapin powershell cmdlet
 
 
 
Now powershell switch to version 2, we can run powershell cmdlets ..
 
 
Thats it...