Archive

Archive for giugno 2013

SP2010 – Powershell per inserimento Conten Type

#Comando per eseguire le istruzioni Sharepoint/Powershell (da eseguire una sola volta all'inizio)
#Add-PSSnapin microsoft.sharepoint.powershell

# PARAMETRI
#----------- 
#URL del sito 
$parUrl = "http://myServer:12345/"  
$parSite = get-spsite $parUrl

$parWeb = $parsite.openweb() 

# Nome Content Type 
$parctypeName = "Nome Content Type"  
# Gruppo: se non specificato, inserisce nel gruppo di DEFAULT (Custom Content Type), altrimenti specificare il Gruppo (esistente oppure un nuovo gruppo) 
$parCTGroup = "Nuovo Gruppo TEST" 

# Parent del Content Type (Document, Item,...) 
$parParent = "Item" 

# Descrizione del Content Type 
$parDescription = "Descrizione..." 

# ESECUZIONE 
#------------ 
$ctypeParent = $parWeb.availablecontenttypes[$parParent] 

$ctype = new-object Microsoft.SharePoint.SPContentType($ctypeParent, $parWeb.contenttypes, $parctypeName) 

$ctype.Description = $parDescription 
$ctype.Group = $parCTGroup 

# Aggiunge il Content Type 
$parWeb.contenttypes.add($ctype) 

# definisco i campi del Content Type che ho creato 
#$web.fields.add("Campo1", ([Type]"Microsoft.SharePoint.SPFieldType")::Text, $false) 
#$web.fields.add("Campo2", ([Type]"Microsoft.SharePoint.SPFieldType")::Text, $false)
  
# Creo le Site Column e definisco il gruppo (delle site column non del Content Type) in cui inserirle (Inserire il Gruppo esistente oppure il nuovo gruppo) 
$fieldXML1 = '<Field Type="Text" Name="Campo1" Description="Descrizione Campo 1" DisplayName="Campo1" Group="NuovoGruppoColumn" Hidden="FALSE" Required="FALSE" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInListSettings="TRUE" ShowInNewForm="TRUE" StaticName="Campo1"></Field>' 
$parWeb.Fields.AddFieldAsXml($fieldXML1) 

$fieldXML2 = '<Field Type="Text" Name="Campo2" Description="Descrizione Campo 2" DisplayName="Campo2" Group="NuovoGruppoColumn" Hidden="FALSE" Required="FALSE" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInListSettings="TRUE" ShowInNewForm="TRUE" StaticName="Campo2"></Field>' 
$parWeb.Fields.AddFieldAsXml($fieldXML2) 

# CHOICE 
$fieldXML3 = '<Field Name="Campo3" Type="Choice" DisplayName="Campo3" Format="RadioButtons" Group="NuovoGruppoColumn" Hidden="FALSE" Required="FALSE" FillInChoice="FALSE" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInListSettings="TRUE" ShowInNewForm="TRUE" StaticName="Campo3"><Default>Scelta1</Default><CHOICES><CHOICE>Scelta1</CHOICE><CHOICE>Scelta2</CHOICE></CHOICES></Field>'
 
$parWeb.Fields.AddFieldAsXml($fieldXML3) 

# MULTIPLE LINE OF TEXT 
$fieldXML4 = '<Field Type="Note" Name="Campo4" Description="Descrizione Campo 4" DisplayName="Campo4" Group="NuovoGruppoColumn" Hidden="FALSE" Required="FALSE" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInListSettings="TRUE" ShowInNewForm="TRUE" NumLines="6" RichText="FALSE" Sortable="FALSE" StaticName="Campo4"></Field>' 
$parWeb.Fields.AddFieldAsXml($fieldXML4)  
# NUMBER 
$fieldXML5 = '<Field Type="Number" Name="Campo5" Description="Descrizione Campo 5" DisplayName="Campo5" Group="NuovoGruppoColumn" Hidden="FALSE" Required="FALSE" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInListSettings="TRUE" ShowInNewForm="TRUE" StaticName="Campo5"></Field>' 
$parWeb.Fields.AddFieldAsXml($fieldXML5) 

#DATETIME 
$fieldXML6 = '<Field Type="DateTime" Name="Campo6" Description="Descrizione Campo 6" DisplayName="Campo6" Group="NuovoGruppoColumn" Hidden="FALSE" Required="FALSE" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInListSettings="TRUE" ShowInNewForm="TRUE" StaticName="Campo6" Format="DateOnly"></Field>' 
$parWeb.Fields.AddFieldAsXml($fieldXML6)  

$field1 = $parWeb.fields.getfield("Campo1") 
$field2 = $parWeb.fields.getfield("Campo2") 
$field3 = $parWeb.fields.getfield("Campo3") 
$field4 = $parWeb.fields.getfield("Campo4") 
$field5 = $parWeb.fields.getfield("Campo5") 
$field6 = $parWeb.fields.getfield("Campo6") 

$fieldLink1 = new-object Microsoft.SharePoint.SPFieldLink($field1) 
$fieldLink2 = new-object Microsoft.SharePoint.SPFieldLink($field2) 
$fieldLink3 = new-object Microsoft.SharePoint.SPFieldLink($field3) 
$fieldLink4 = new-object Microsoft.SharePoint.SPFieldLink($field4) 
$fieldLink5 = new-object Microsoft.SharePoint.SPFieldLink($field5) 
$fieldLink6 = new-object Microsoft.SharePoint.SPFieldLink($field6) 

$ctype.fieldlinks.add($fieldLink1) 
$ctype.fieldlinks.add($fieldLink2) 
$ctype.fieldlinks.add($fieldLink3) 
$ctype.fieldlinks.add($fieldLink4) 
$ctype.fieldlinks.add($fieldLink5) 
$ctype.fieldlinks.add($fieldLink6)   
$ctype.Update() 

$parWeb.Dispose() 

$parSite.Dispose() 
Categorie:SharePoint