Tuesday, September 9, 2014

Programmatically Change Default Content Type in SharePoint 2013 List

 

SharePoint list does not have any direct property or method to make content type default. but it is having content type ordering. thus making content type in first of the list automatically makes that content type default.

following shows a sample code

using (var site = new SPSite("url"))
{
   using (var web = site.AllWebs["yourweb"])
   {
       var lst = web.Lists["Your List"];
   
       SPContentTypeCollection currentOrder = lst.ContentTypes;
 
       // make default content type
       var newOrder = currentOrder.Cast<SPContentType>().Where(ct => ct.Name.Contains("Content Type To Default")).ToList();
       lst.RootFolder.UniqueContentTypeOrder = newOrder;
       lst.RootFolder.Update();            
   }
}
 
 

Friday, September 5, 2014

The Managed Metadata Service or Connection is currently not available. The Application Pool or Managed Metadata Web Service may not have been started. Please Contact your Administrator.

 

ManagedMetadataServiceError

I noticed this error when I logged to SharePoint farm; Meta Data service application.

Tasks going to perform

  • Get the Current Mapped Data Base for Managed Meta Data Service
  • Backup Data Base and get the name
  • Delete Meta Data Service Application with out Data Base
  • Create a New Managed Meta Data Service with new Application Pool
  • Change the Data base reference to old database

When I googed I found few resolutions which didn’t work for me. so I tried a slightly different approach which worked for me.

Get the Current Mapped Data Base for Managed Meta Data Service

Go to central admin and navigate to Manage Meta Data Service properties to find out mapped data base.

image

image

Then go to your database server and backup the database for recovery purposes. (this step is not mandatory but good for safe side)

Delete Meta Data Service Application with out Data Base

image

image

Create a New Managed Meta Data Service with new Application Pool

image

When you creating specify a new data base name (DB1) and new application pool.

 Change the Data base reference to old database

after that go to Managed Meta Data Properties (like first step) and change the Data Base name to original one.

in my case DB1 –> MetaData 

Tuesday, August 26, 2014

An error occurred while talking to SMTP host mail.something.local Event ID 6858

this error occurred to me when I setup SMTP virtual sever for SharePoint farm. then I tried to trouble shoot email sending using PowerShell and it also return False.

Trouble shooting SharePoint Emails (SMTP server) 

$dict = new-object System.collections.specialized.stringdictionary
// recipient's Email Address
$dict .add("to","somebosy@gmail.com")
// sender: you can put anything that you want to visible in the email
$dict .add("from","outsender@sharepoint.local")
$dict .add("Subject","sample subject")
// this is any existing sp web url
$web = get-spweb "http://4587wfe2013:5003"
$body = "This is our body codes in it."
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web,$sd,$body)

This code will return True if success otherwise will be False.


This error occurred me because of connection issues to SMTP server. thus I go to SMTP properties


 image


Then go to Access Tab and click Connection and Relay buttons and make the radio selection to all except to list below.


image


image