Sort Folders (Custom Order) in SharePoint Document Library

Sort Folders (Custom Order) in SharePoint Document Library

One of my friend recently asked me this question about sorting the folders (not in alphabetical order) in a document library. The sort order has to be custom and user should be able to specify the order in which folders should appear. Example sort order

 

Top

Middle

Bottom

 

 

In order to implement this you can create a new folder content type and add an order column to this content type. You do need to have the appropriate rights to do so.

 

The steps would be as follows.

·         Go to Site Actions

·         Go to Site Settings

·         Go to Site Content Types

·         Click Create New

·         Give it a name such as Folder Order

·         Select Parent Content Type from as of Folder Content Types

·         Select Folder as the Parent Content Type

·         You can create a new group or leave it in custom content types

·         Click OK

·         At the content type settings click Add from new site column

·         Create a site column called Item Order or something similar, select the type as Number

·         Click OK

·         Go to the list where you want the folders to be ordered

·         Go to the list settings

·         Go to Advanced Settings

·         Select allow management of content types

·         Select No for display new folder command on the new menu

·         Click OK

·         You should now see an area called content types, leave the document as is

·         Click Add from existing site content types

·         Select the Folder Order (or whatever you named it)

·         Click OK







Create a Custom Action Specific to a List for SharePoint 2013/SharePoint 2010

You can create a custom action that is based on the list type by editing the elements.xml file that is associated with the custom feature. However, you can also create a custom action that is specific to a list rather than a list type. To do this, create a custom feature for the content type and then make a minor modification in the elements.xml file. The following steps demonstrate how to do this.

Create a custom content type

  1. Create a custom content type by inheriting from any one of the standard Windows SharePoint Services content types.

  2. Ensure that the identifier (ID) of your custom content type has the ID of the base content type (from which it inherits) as its ID prefix.

    The following example XML code shows the elements.xml file for a custom content type that was inherited from the standard Windows SharePoint Services content type, in this case, the List content type.
    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <ContentType ID="0x01AB"
         Name="MyCustomContentType"
         Group="MyCustomContentTypeGroup"
         Description="Customized Content Type"
         Version="0">
       <FieldRefs>
        <FieldRef ID="{8c06beca-0777-48f7-91c7-6da68bc07b69}"
         Name="Created"
         DisplayName="Field1" />
        <FieldRef ID="{1df5e554-ec7e-46a6-901d-d85a3881cb18}"
         Name="Author"
         DisplayName="Field2" />
       </FieldRefs>
      </ContentType>
    </Elements>

    Create your custom action

    • In the Elements.xml file, create your custom action, as illustrated in the example following.
      <?xml version="1.0" encoding="utf-8" ?>
      <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <!-- Document Library Toolbar New Menu Dropdown -->
         <CustomAction Id="UserInterfaceLightUp.DocLibNewToolbar"
          RegistrationType="ContentType"
          RegistrationId="0x01AB"
          Rights="ManagePermissions"
          Location="EditControlBlock"
          Sequence="1000"
          Title="MY DOCLIB NEW MENU TOOLBAR BUTTON">
         <UrlAction Url="/_layouts/LightupHello.aspx?NewMenu"/>
        </CustomAction>
      </Elements>

      Create the list

      1. Create the list where you want to render the custom action.

      2. Change the default content type of the new list to the custom content type that you created above.

      3. Delete the Item content type from the list. At this point, the custom action will be rendered in the Edit Control Block menu of the specified list.





Enable The SharePoint Learning Kit Feature On All Sites In A Site Collection

Sometimes you want to be able to assign work from anywhere within your site collection. For the E-Learning Actions custom action to be added to a document library you need to enable the SharePoint Learning Kit feature on that site, so to enable it everywhere you need to enable the feature on all sites.

To do this in SharePoint 2010 all you need is a simple PowerShell script which iterates through all the sites and then enables the feature if it is not already enabled. The following script will do that for you. You will need to change the url value to reference your site collection, save in a .ps1 file and then run from the SharePoint 2010 Management Shell.

$url = "http://urlOfSiteCollection"  $site = Get-SPSite $url  $featureId = "00057002-c978-11da-ba52-00042350e42e"  $featureName = "SharePointLearningKit"  $site.Urlforeach ($web in $site.AllWebs)  {      # Output the site url for debugging purposes      $web.Url      # Only enable if not already enabled      if (!$web.Features[$featureId])      {          # Output debugging message          "Enabling..."          Enable-SPFeature $featureName -Url $web.Url      }  }

You can also use this for other features, just by replacing the feature id and name with the appropriate values. To find these look in

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES

The feature name is the name of the folder in here and the id is in the feature.xml file in that folder.



Using PowerShell to Bulk Upload Files to SharePoint 2013/SharePoint 2010

While building a school's Learning Gateway I needed to bulk upload all their student images into a picture library so that the My Children web part could display them. Since there were several hundred of them I wrote a little PowerShell script to perform this.

$siteUrl = "http://sharepoint/schools/test" $listName = "Students Picture Library"  [system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint") $site = New-Object Microsoft.SharePoint.SPSite($siteUrl) $web = $site.OpenWeb()$list = $web.Lists[$listName] $fileCollection = $list.RootFolder.Files  $files = get-childItem -Exclude *.ps1  foreach ($file in $files) {     $stream = $file.OpenRead()     $uploaded = $fileCollection.Add($file.Name, $stream, $TRUE)     "Uploaded " + $file.Name      if ($stream) {$stream.Dispose()} }  if ($web) {$web.Dispose()} if ($site) {$site.Dispose()}

In order to use this:

  1. Save as as .ps1 file in the same folder as the files to upload.
  2. Change the site url and name of the list at the beginning of the script to your values
  3. Make sure that only the files to upload and the ps1 file is in the folder
  4. Open PowerShell using Run As Administrator
  5. Navigate to the folder
  6. Run the .ps1 file

The script will then iterate through all files in the current folder and upload them to the given list, overwriting them if they already exist.