Thursday, December 29, 2011

Programmatically remove fields from content type

You should delete fields from content type using the FieldLinks collection.




When applying site content types to lists, the content type is copied to the list. If you change the content type on the list (for example, add or remove columns), the "parent" and all the same content types on other lists won't be changed.



You have two option. If you want to change only the list content type, but not the related site content type:

using (SPWeb web = site.OpenWeb())

{

SPList list = web.Lists["YourList"];

SPContentTypeCollection cts = list.ContentTypes;

SPContentType ct = cts["YourContentType"];

ct.FieldLinks.Delete("YourField");

ct.Update();

}



If you want to change the site content type, you should go with the code below:

using (SPWeb web = site.OpenWeb())

{

SPContentTypeCollection cts = web.ContentTypes;

SPContentType ct = cts["YourContentType"];

ct.FieldLinks.Delete("YourField");

// calling the update with true will copy the changes from

// site content types to all list content type instance

ct.Update(true);

}

Remove column from content type using powershell script

http://get-spscripts.com/2010/10/cant-remove-site-column-from-content.html


The example below will remove the “Aliases” site column from the “Sales Document” site content type in http://portal:




#Attach to the web and content type

$web = Get-SPWeb http://portal

$ct = $web.ContentTypes["Sales Document"]



#Get link to the columnn from the web

$spFieldLink = New-Object Microsoft.SharePoint.SPFieldLink ($web.Fields["Aliases"])



#Remove the column from the content type and update

$ct.FieldLinks.Delete($spFieldLink.Id)

$ct.Update()



#Dispose of the web object

$web.Dispose()

Note that any columns of this type deleted from a parent content type will not automatically disappear in the child content types below it. The easiest way to get around this is to use the same script above to remove the site column from child content types, too.




Unfortunately, you may also find that if the content types containing this site column were attached to lists, then the lists themselves will also have the column added to them – even after removing the column from all associated content types. If this is the case, you will not be able to remove the column in the list using the browser UI as the Remove button will be missing on the column administration page here also.



To resolve this, you can either decide to remove the column using PowerShell one list at a time, or if there is a way of defining a batch of lists, use a script to modify multiple lists in one go. The script below provides you with an example of how to walk through each document library of a specified name on each site of the site collection and delete the offending column. If you do decide to run a script like this, please ensure you have fully tested it in a development environment beforehand due to the potential damage that it could inflict:



#Delete column on a specified list in all sites of a site collection

$site = Get-SPSite http://portal

$site
Get-SPWeb -Limit all
ForEach-Object {

#Specify list which contains the column

$list = $_.Lists["Pages"]

#Specify column to be deleted

$field = $list.Fields["Aliases"]

#Allow column to be deleted

$field.AllowDeletion = $true

#Delete the column

$field.Delete()

#Update the list

$list.Update()

}

$site.Dispose()

Content Types Event Receivers

http://pietersveenstra.wordpress.com/2011/12/12/removing-multiple-event-handlers-from-content-type-or-list/

http://charliedigital.com/2010/10/06/programmatically-adding-an-event-receiver-to-a-content-type/


http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/ffc35fd4-2b26-4e56-a924-a3b9d9e25e6b

Tuesday, December 27, 2011

Search Center Links

http://www.businessintelligencetoday.com/1/post/2011/4/setting-up-a-search-center-in-sharepoint-2010.html




http://www.sharepoint911.com/blogs/john/archive/2011/06/10/using-tabs-in-the-enterprise-search-center-in-sharepoint-server-2010.aspx



http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/897c6a75-3a8f-4a86-9621-195b9d6fafbe

Workflow Codes

Workflow status codes (used for view filter)



Here is the list of the status codes used to maintain the workflow statuses. This list might be useful when anyone creates a view based on workflow status. If you are creating a view for a list filtered by the workflow status, you would need use the number rather than the words (e.g. 2 instead of In Progress, 4 instead of Cancelled etc)



Status Value

Not Started 0

Failed on Start 1

In Progress 2

Error Occurred 3

Canceled 4

Completed 5

Failed on Start (retrying) 6

Error Occurred (retrying) 7

Canceled 15

Approved 16

Rejected 17