Friday, 27 April 2012

Provision Content Type via XML


In your solution Explorer add the content type item.


click add, next select the base content type Item to inherit from.


Once selected click finish, and you're ready to start provisioning your content type


to quickly explain some of the properties
  • ID: unique id of the content type, in this case 0x0100 is the Id for item, the following hex number is a GUID
  • Name: this is the a readable name, make it short and sweet
  • Group: helps you organize your content types, again make it descriptive
  • Description: Lets the user know what your content type is for
  • Inherits: lets your content type to include the columns from and inherited ct's.
  • Version: not too sure, i leave it as 0,
This is what I have for my Coffee Content type


So lets go back and create some Site Columns:
  • Id - unique id
  • Title - Out of the box
  • Region - Choice Field
  • Supplier - look up list
  • Start Date - Date with default value of today
  • Price - Price Per Ton
Create Custom Site Columns

With our Custom Site columns made we can load them into our Content type we add them to our content type

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Parent ContentType: Item (0x01) -->
  <ContentType ID="0x01004640ea11f8fd45f9b930ada1806ab7dd"
               Name="Coffee"
               Group="Custom Coffee"
               Description="Content type for Coffee"
               Inherits="TRUE"
               Version="0">
    <FieldRefs>
      <FieldRef ID="{9749FAFE-B58C-4945-85B9-C360C5E309C1}" Name ="CoffeeID" DisplayName="Coffee ID" Required ="TRUE"/>
      <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Coffee Name" Required="TRUE" />
      <FieldRef ID="{FE2F4BE0-6FB3-4EC6-922B-FA3641745EC5}" Name="CoffeeRegion" DisplayName="Region" Required="TRUE"/>
      <FieldRef ID="{A4AC9AEE-3FD3-457F-A8D6-50C0E86363B6}" Name="CoffeeSupplier" DisplayName="Supplier" Required="TRUE"/>
      <FieldRef ID="{4206013B-2B16-441B-A6AD-2E1DAE6C4A86}" Name="CoffeeStartDate" DisplayName="Start Date" Required="TRUE"/>
      <FieldRef ID="{EFE8441B-8A51-427D-ABF4-D9D4ECB1F2E9}" Name="CoffeePrice" DisplayName="Price" Required="TRUE"/>
    </FieldRefs>
  </ContentType>
</Elements>


With our content type set up we can proceed to make a list definition next.

Friday, 6 April 2012

Too Many Webparts!!!

The page '/_catalogs/masterpage/somepage.aspx' allows a limit of 11 direct dependencies, and that limit has been exceeded.


 This Error is the result of having too many Web Parts on one page, luckily it's an easy fix.

navigate to C:\inetpub\wwwroot\wss\VirtualDirectories
here pick the port to your site, 80 is the default.
Navigate to the port number and then open the web.config, it's an xml. I suggest using Notepad++.
Once you have your web-config file open do a find on the term DirectFileDependencies
then simply change the number of the property DirectFileDependencies to something higher.

 
Just Save, reload your page  and presto everything is alright again.

Thursday, 5 April 2012

Provision Unique site Column

Make sure to include the highlighted properties. 
<Field ID="{E9ADC1A3-C044-4C99-AB48-AFAD5F657648}"
  Group ="Custom"
  DisplayName="Id Number"
  Name="CCWIdNumber"
  Type="Text"
  EnforceUniqueValues="TRUE"
  Indexed="TRUE"
  Required="TRUE"
  ShowInDisplayForm="TRUE"
  ShowInNewForm="TRUE"
  ShowInEditForm="TRUE" />
One thing to note is that you can't share this field in a document set
if you've found a way please let me know.

Tuesday, 27 March 2012

Activate Document Set Feature

What is a document set?
Remember Document sets are NOT available in SharePoint foundation.
Site Settings
    Site Collection Administration
        Site Collection Features

   











Once in the feature list hit the activate button for document sets.


function LoadSharePointPowerShellEnviroment
{
 write-host
 write-host "Setting up Powershell enviroment for Sharepoint" -foregroundcolor Blue
 Add-PSSnapin "Microsoft.Sharepoint.PowerShell" -ErrorAction SilentlyContinue
 Write-host "Sharepoint PowerShell Snapin loaded." -foregroundcolor Green
}
 
write-host
LoadSharePointPowerShellEnviroment
 
write-host
write-host "Activating the Document Set Feature" -foregroundcolor Blue
Enable-SPFeature -Identity DocumentSet -url "http://ssrap2"
write-host "Document Set Feature activated" -foregroundcolor Green

Make sure to sub in your site URL where it's highlighted in yellow.

or if you're really bad-ass activate it in your feature receiver

private Guid DocumentSetFeatureID = new Guid("3bae86a2-776d-499d-9db8-fa4cdc7884f8");
        
// Uncomment the method below to handle the event raised after a feature has been activated.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    using (SPSite site = properties.Feature.Parent as SPSite)
    {
        if (site.Features[DocumentSetFeatureID] == null)
        {
            site.Features.Add(DocumentSetFeatureID);
        }
    }
}

Friday, 23 March 2012

List Existing site Columns using Powershell

Powershell script

[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

function GetSiteColumns($web)
{
    foreach ($f in $web.Fields)
    {
        $data = @{"Id" = $f.Id
                  "Title" = $f.Title
                  "Type" = $f.Type
                  "Internal Name" =  $f.InternalName
                   "Group" = $f.Group
                  }
                  New-Object PSObject -Property $data   
    }
}

$webUrl = "http://ssrap2"
GetSiteColumns(Get-SPWeb $webUrl) | Out-GridView

remember to swap out the url highlighted in yellow to your own, for this to work you need to have windows powershell ISE installed.

I've been uping my PowerShell skills as of late,
and here's a much more impressive way to achieve the same result


#function to load SharePoint Powershell snap in
function LoadSharePointPowerShellEnviroment
{
 #clear the screen of pevious output
 Clear-Host
 write-host "Setting up Powershell enviroment for Sharepoint" -foregroundcolor Blue
 Add-PSSnapin "Microsoft.Sharepoint.PowerShell" -ErrorAction SilentlyContinue
 Write-host "Sharepoint PowerShell Snapin loaded." -foregroundcolor Green
}
#call sharepoint plugin function
LoadSharePointPowerShellEnviroment
$web = Get-SPWeb("http://Wingtip")
$web.Fields | Select-Object -Property id, Title, type,InternalName, Group  | Out-GridView
$web.dispose()

Sunday, 18 March 2012

Custom Site Column

First we need to create an empty element object, To do this right click in your Solution explorer, select add a new item and choose an empty element



Click the "Add" button and presto, your ready to make a Site column

Once you have your empty elements file open you're ready to create your custom site column(s) you can start creating fields (columns), below I've created five all with unique ID's

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 
  <Field ID ="{9749FAFE-B58C-4945-85B9-C360C5E309C1}"
         Name ="CoffeeID"
         DisplayName ="Coffee ID"
         Group="Coffee"
         Type="Text"
         EnforceUniqueValues="TRUE"
         Required="TRUE"
         Indexed="TRUE"
           ShowInDisplayForm="TRUE"
         ShowInNewForm="TRUE"
         ShowInEditForm="TRUE"/>
  
  <Field ID="{FE2F4BE0-6FB3-4EC6-922B-FA3641745EC5}"
         Name ="CoffeeRegion"
         DisplayName ="Coffee Region"
         Group ="Coffee"
         Type ="Choice"
         Required ="True"
           ShowInDisplayForm="TRUE"
         ShowInNewForm="TRUE"
         ShowInEditForm="TRUE">
    <CHOICES>
      <CHOICE>Africa</CHOICE>
      <CHOICE>Asia</CHOICE>
      <CHOICE>Europe</CHOICE>
      <CHOICE>North America</CHOICE>
      <CHOICE>Oceania</CHOICE>
      <CHOICE>South America</CHOICE>
    </CHOICES>
  </Field>
 
  <Field ID ="{A4AC9AEE-3FD3-457F-A8D6-50C0E86363B6}"
       Group ="Coffee"
       DisplayName ="Coffee Supplier"
       Name ="CoffeeSupllier"
       Type ="Lookup"
       List="Lists/CoffeeSupplier"
       OverwriteInChildScopes="TRUE"
       Overwrite="TRUE" />
 
  <Field ID ="{4206013B-2B16-441B-A6AD-2E1DAE6C4A86}"
     Name ="CoffeeStartDate"
     DisplayName ="Coffee StartDate"
     Group="Coffee"
     Type="DateTime"
     Format="DateTime">
    <Default>[today]</Default>
  </Field>
 
  <Field ID ="{EFE8441B-8A51-427D-ABF4-D9D4ECB1F2E9}"
         Name ="CoffeePrice"
         DisplayName ="Coffee Price"
         Group ="Coffee"
         Type="Number"
         Required="TRUE" />
</Elements>

And it's that that easy, there are numerous type's of Columns, refer to MSDN for a full list