Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:


Recycle Bin | MMS | ManagedVsCrawledProperties |
Showing posts with label SPFieldChoice. Show all posts
Showing posts with label SPFieldChoice. Show all posts

Friday, November 14, 2014

SharePoint choice field using powershell

$docSite = new-object Microsoft.SharePoint.SPSite($siteURL)
$docWeb = $docSite.OpenWeb()
$lncustomListName listName
$CustomfieldName = "MyChoiceColumn"

/* To create choice field */
Add-SPMultiChoiceField -listName $lncustomListName

/* Method to create choice field */
function Add-SPMultiChoiceField([string]$listName)
{
  $OpenList = $docWeb.Lists[$listName]
  $multiChoiceCol = "<Field Name='"+ $CustomfieldName +"' Type='MultiChoice' FillInChoice='FALSE' DisplayName='"+ $CustomfieldName +"'><Default>MyChoice1</Default><CHOICES><CHOICE>MyChoice2</CHOICE><CHOICE>ERM</CHOICE><CHOICE>MyChoice3</CHOICE></CHOICES></Field>"
 $OpenList.Fields.AddFieldAsXml($multiChoiceCol,$true,
 [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView) 
}

Thursday, November 29, 2012

SPFieldChoice to the dropdown list programatically:


  1. List Name: MyList
  2. Choice Field Name: MyChoiceField and the values are
    1. MyChoice1
    2. MyChoice2
    3.  MyChoice3
First example to set the SPChoice field default value as dropdown list default value.


          try
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                {
                    SPWeb web = site.OpenWeb(SPContext.Current.Web.ID);
                    SPList liMyLists = web.Lists["MyList"];
                    SPFieldChoice fcTypes = (SPFieldChoice)       
                                                liMyLists.Fields["MyChoiceField"];
                    ddlChoiceField.DataSource = fcTypes.Choices;
                   //To set choice field default value as dropdown list default value.
                    ddlChoiceField.SelectedValue = fcTypes.DefaultValue; 
                    ddlChoiceField.DataBind();
            }
            catch (Exception ex)
            {
               //code
             }
OutPut: