How to ReOrder SharePoint List Items using Custom Code/PowerShell and SharePoint Designer in SharePoint 2010 and SharePoint 2013

The functionality to “Reorder list items” is inbuilt for “Links” lists both in SharePoint 2010 and SharePoint 2013.

051513_0103_HowtoReOrde1.png

   “Change Item Order” option in SharePoint 2013 Links List.

051513_0103_HowtoReOrde2.png

 “Change Item Order” option in SharePoint 2010 Links List.

 How does this “Change Item Order” button work?

SharePoint uses hidden column “order” to set the order. When we select the “Change Item Order” option, SharePoint uses “/_Layouts/Reorder.aspx?List=ListGUID” page to reorder the list items.

But this wonderful feature is hidden for other list templates and only available with OOTB Links Lists. I wonder why?

 In this blog post I have listed different methods we can use to enable this feature for other lists.

 Method 1: Use Console Application/PowerShell script. This method is preferable because we can reuse it for different lists with ease. We just need to provide the site url and the list name.

 C# Console Application You can download this file from here.

using Microsoft.SharePoint;
namespace ReOrderSharePointListItems
{
  class ReOrderSharePointListItems
  {
    static void Main(string[] args)
    {
      using (var site = new SPSite("yourSiteCollectionUrl"))
      {
        using (var web = site.OpenWeb())
        {
          var list = web.Lists["yourListTitle"];
          SetButton(list, web);
          SetOrder(list, web);
        }
      }
    }

   /// <summary>
   /// Set Button "Change Item Order" in
   /// Top Ribbon of List
   /// </summary>
   /// <param name="list"></param>
   /// <param name="web"></param>
  static void SetButton(SPList list, SPWeb web)
  {
    list.UserCustomActions.Clear();
    SPUserCustomAction action = list.UserCustomActions.Add();
    action.Location = "CommandUI.Ribbon";
    action.Sequence = 85;
    action.Title = "PS.OrderItems";
    action.Rights |= SPBasePermissions.EditListItems;
            action.CommandUIExtension =
    string.Format(
    @"<CommandUIExtension>
    <CommandUIDefinitions>
    <CommandUIDefinition
            Location=""Ribbon.ListItem.Actions.Controls._children"">
    <Button Id=""ReOrderAction.Button""
            TemplateAlias=""o1"" Command=""ReOrderCommand""
            CommandType=""General"" LabelText=""Change Item Order""
    Image16by16=""/_layouts/1033/images/formatmap16x16.png""
            Image16by16Top=""-192"" Image16by16Left=""-144""
    Image32by32=""/_layouts/1033/images/formatmap32x32.png""
            Image32by32Top=""-192"" Image32by32Left=""-288""/>
    </CommandUIDefinition>
    </CommandUIDefinitions>
            <CommandUIHandlers>
    <CommandUIHandler Command =""ReOrderCommand""
            CommandAction=""{0}/_layouts/reorder.aspx?List={1}"" />
    </CommandUIHandlers>
            </CommandUIExtension>",
    web.ServerRelativeUrl.TrimEnd('/'), list.ID);
    action.Update();
  }

  /// <summary>
  /// Order Default view by field "order"
  /// </summary>
  /// <param name="list"></param>
  /// <param name="web"></param>
  static void SetOrder(SPList list, SPWeb web)
  {
    SPView view = list.DefaultView;
    view.Query = @"<OrderBy><FieldRef Name=""Order""
                         Ascending=""TRUE""/></OrderBy>";
    view.Update();
  }
 }
}

PowerShell Script: You can download this script from here.

[void] [System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | out-null
# Add "Change item Order" button at target List
$siteUrl = "yourSiteCollectionUrl";
$listTitle = "yourListTitle";
$site = Get-SPSite -Identity $siteUrl;
$web = $site.OpenWeb();
$list = $web.Lists[$listTitle];
$list.UserCustomActions.Clear();
$action = $list.UserCustomActions.Add();
$action.Location = "CommandUI.Ribbon";
$action.Sequence = 85;
$action.Title = "PS.OrderItems";
$action.CommandUIExtension =
[string]::Format(
"<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
  Location=""Ribbon.ListItem.Actions.Controls._children"">
<Button Id=""ReOrderAction.Button"" TemplateAlias=""o1""
  Command=""ReOrderCommand"" CommandType=""General""
  LabelText=""Change Item Order""
Image16by16=""/_layouts/1033/images/formatmap16x16.png""
  Image16by16Top=""-192"" Image16by16Left=""-144""
Image32by32=""/_layouts/1033/images/formatmap32x32.png""
  Image32by32Top=""-192"" Image32by32Left=""-288""/>
</CommandUIDefinition>
</CommandUIDefinitions>
  <CommandUIHandlers>
<CommandUIHandler Command =""ReOrderCommand""
  CommandAction=""{0}/_layouts/reorder.aspx?List={1}"" />
</CommandUIHandlers>
 </CommandUIExtension>",
$web.ServerRelativeUrl.TrimEnd('/'), $list.ID);
$action.Update();
$view = $list.DefaultView;
$view.Query = [string]::Format("<OrderBy><FieldRef Name=""Order""
Ascending=""TRUE""/></OrderBy>");
$view.Update();
Write-Host "-------------------------------------"
Write-Host "Change item order button added successfully for
the list :  " $list.Title -foregroundcolor Green -nonewline
Write-Host " in the site  : " $site.Url -foregroundcolor Green
Write-Host "-------------------------------------"
$web.Dispose();
$site.Dispose();

Method 2: Use SharePoint designer and PowerShell.

1. Since “order” column is hidden, we need to use following PowerShell script to make this field visible. Once this field is visible, we can use it in List Views. You can download this script from here.

# Change List Schema to unhide order field.
$siteUrl = "yourSiteUrl;
$listTitle = "yourListTitle";
$site = Get-SPSite -Identity $siteUrl;
$web = $site.OpenWeb();
$list = $web.Lists[$listTitle];
$field=$list.Fields["Order"];
$field.SchemaXml=
$field.SchemaXml.Replace("Hidden=""TRUE""","Hidden=""FALSE""");
Write-Host "-------------------------------------"
Write-Host "Order field is set to visible in
list :  " $list.Title -foregroundcolor Green -nonewline
Write-Host " in the site  : " $site.Url -foregroundcolor Green
Write-Host "-------------------------------------"
$web.Dispose();
$site.Dispose();

2. Open the list in SharePoint Designer

3. Click on “Custom Actions” and then select “View Ribbon”

051513_0103_HowtoReOrde3.png

4. Enter following information.

  • Name : “Change Item Order”
  • Navigate to URL:  {SiteUrl}/_layouts/Reorder.aspx?List={ListGUID}
  • Button Image URL (16×16): {SiteUrl}/_layouts/1033/images/formatmap16x16.png
  • Button Image URL (32×32): {SiteUrl}/_layouts/1033/images/formatmap32x32.png

051513_0103_HowtoReOrde4.png

5. Click OK. This will add the custom action in the list ribbon as shown below.

051513_0103_HowtoReOrde5.png

 

6. Next step is to modify the default view of the list and sort the items by field “Order”.

051513_0103_HowtoReOrde6.png

7. All set.

Note : “Change Item Order” option does not modify the version history of list items. So if you are using Content Deployment, reordering the list items will not move changes to target environment.

Posted in SharePoint 2013, SharePoint 2013 Development | Tagged , , , , , , , , | Leave a comment

SharePoint 2013 Installation Guide – Development Environment

SharePoint 2013 Installation Guide – Development Environment

In this blog post I have document the steps for creating your own SharePoint 2013 development environment.

Unlike SharePoint 2010, you can’t install domain controller and SharePoint 2013 in same server if you would like to use workflow manager and office Web Apps. If you would like to install Workflow manager and Office WebApps then we need at least two virtual machines, one with domain controller and another with SharePoint 2013 and SQL Server.

Note: If you don’t have MSDN licenses then you can sign up for preview licenses and in most cases those will be good for 3 to 6 months.

Domain Controller Virtual Machine:

First step is to create a domain controller virtual machine (VM1).  Operating system for Domain Controller VM can be Windows Server 2003, Windows Server 2008 or Windows Server 2012. Once you install the operating system, configure Active Directory Domain Services. You can find the steps here. http://technet.microsoft.com/en-us/library/cc755059(v=ws.10).aspx

You can give nice domain name for your test setup. For example: sharepointlab.com

Note: We don’t need lot of RAM for Domain controller. 512MB or 1GB is more than enough.

SharePoint 2013 Virtual Machine:

Once the domain server (VM1) is up and running, create virtual machine for SharePoint 2013 server (VM2).

Hardware and Software Requirements:

Following is the summary of the hardware and software requirements for SharePoint 2013 server.  For detailed hardware and software requirements please check this out. http://technet.microsoft.com/en-us/library/cc262485.aspx

  • RAM: 8 GB (Minimum)
  • Hard disk Space: 80GB
  • Processor: 64bit and 4 core
  • Operating System: 64-bit edition of Windows Server 2008 R2 Service Pack 1 (SP1) Standard, Enterprise, or Datacenter or the 64-bit edition of Windows Server 2012 Standard or Datacenter
  • SQL: 64-bit edition of Microsoft SQL Server 2012 or 64-bit edition of SQL Server 2008 R2 Service Pack 1

Note: If your domain controller VM has required operating system for SharePoint 2013, you can make copy of that VM to install SharePoint 2013. You have to run sysprep on the copied VM. Sysprep can be run from “C:\windows\System32\sysprep”. Sysprep will wipe out SID, machine name and custom network settings. Also you have to re-activate the windows.

Setup up internal network between Domain Controller and SharePoint 2013 Server:

After operating system is installed on the VM2, setup the internal network between VM1 and VM2.You can assign the static IP addresses for VM1 and VM2 as follows.

VM1: Use the Following IP Address Internet Protocol Version 4 (TCP/IPv4) settings
(feel free to use the ip addresses of your choices):

  • IP Address: 192.168.150.102
  • Subnet mast: 255.255.255.0
  • Default Gateway: 192.168.150.1
  • Use the Following DNS Server Addresses:
    • Preferred DNS Server: 192.168.150.2

VM2: Use the Following IP Address Internet Protocol Version 4 (TCP/IPv4) settings:

  • IP Address: 192.168.150.103
  • Subnet mast: 255.255.255.0
  • Default Gateway: 192.168.150.1
  • Use the Following DNS Server Addresses:
    • Preferred DNS Server: 192.168.150.102

Check if you can ping VM1 from VM2 to verify both the VMs are on internal network.

Join VM2 to Domain:

Follow steps mentioned here to attach VM2 to the domain (sharepointlab.com). http://technet.microsoft.com/en-us/library/cc770919(v=ws.10).aspx . You can give the name SharePointLab01 to this VM.

Create Service Accounts:

All the service accounts are required to be domain accounts. Todd O. Klindt has nice blog post on service accounts. http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=237. The steps to create new domain users are here. http://technet.microsoft.com/en-us/library/cc732336.aspx . When choosing service accounts, consider the principle of least privilege. The service account should have exactly the privileges that it needs to do its job and no more privileges. Create the following service accounts in VM1.

  • sharepointab\sp_sql_server
  • sharepointlab\sp_sql_agent
  • sharepointab\sp_admin
  • sharepointab\sp_farm

The following service accounts can be created in VM1 as and when needed.

  • sharepointab\sp_content
  • sharepointab\sp_serviceapps
  • sharepointlab\sp_app_pool
  • sharepointlab\sp_web_app
  • sharepointlab\sp_service
  • sharepointlab\sp_crawl
  • sharepointlab\sp_ups
  • sharepointlab\sp_bi

Make “sharepointab\sp_admin” local admin on VM2.

Install SQL 2012 Server on VM2:

Login to the VM2 using “sharepointab\sp_admin” account and run the setup.exe located inside SQL Server 2012 installation files.

Click Installation on the left-hand side of the SQL Server Installation Center.

SQL2012Installation01

Select “New SQL Server stand-alone installation or add features to an existing installation”.

Installer will check for issues before installation. If there are no errors, then you will get following page.

SQL2012Installation03

On the Setup Support Rules page, click OK.

You can skip product update.

Next page will prompt to enter the license key. Enter evaluation and click Next.

SQL2012Installation04

Accept the license terms and click Next.

The setup will then start installing files as shown below.

SQL2012Installation05

After that “Setup Support Rules” will check and identify if there is any problem that can occur during the installation. Click Next if there are no failures.

SQL2012Installation06

On the Setup Role page, select SQL Server Feature Installation and click Next.

SQL2012Installation07

On the Feature Selection page, check the following options and click Next.

  • Database Engine Services
    • Full-Text and Semantic Extractions for Search
    • Reporting Services – SharePoint
    • Reporting Services Add-in for SharePoint Products
    • Client Tools Connectivity
    • Client tools backward compatibility
    • Management Tools Basics
      • Management Tools Complete

SQL2012Installation08

If the installation fails because of .NET Framework 3.5 service pack 1 then Use the Server Manager to add the feature “.NET Framework 3.5.1. Features”. The steps to add the feature are found here http://technet.microsoft.com/en-us/library/cc732263.aspx#BKMK_add

SQL2012Installation09

If there are no problems, Click Next on the following page.

SQL2012Installation10

In the Instance Configuration, select the default instance and click Next.

SQL2012Installation11

Click Next on the Disk Space Requirements page.

On the Server Configuration page, use the SQL service accounts “sharepointlab\sp_sql_agent” for services SQL Server Agent and “sharepointlab\sp_sql_server” for SQL Server Database Engine. Enter their respective passwords and click Collation. Select collation “Latin1_General_CI_AS_KS_WS” (Latin1-General, case-insensitive, accent-sensitive, kanatype-sensitive, width-sensitive) and then click next.

SQL2012Installation12

 

On the Database Engine Configuration page, add the SQL server Admins. To do that, on the Server Configuration tab, click Add. After adding SQL server admins click Next.

SQL2012Installation13

Click Next on the Reporting Services Configuration Page.

Click Next on the Error Reporting Page.

Click Next on the Installation Configuration Rules Page.

Click Next on the Ready to Install Page.

Installation will take some time depending on the speed/performance of the VM2.

SQL2012Installation14

After completion, setup will prompt to restart the machine as shown below. Click OK and then Close.

SQL2012Installation15

Restart VM2 to complete the installation.

Open SQL Server 2012 Management studio and grant “sharepointlab\sp_admin” SQL Server Roles “dbcreator”, “securityadmin” roles. The steps to add server roles are here. http://technet.microsoft.com/en-us/magazine/hh528496.aspx

Install SharePoint 2012 Server on VM2:

Login to VM2 using “sharepointlab\sp_admin” account and run the splash.hta located inside SharePoint Server 2013 installation files.

First install all prerequisites. During this process the VM2 will need access to internet. The VM2 will restart several times. When all the prerequisites are installed you will see following page.

SP2013Installation01

Click “Install SharePoint Server”.

SP2013Installation02

Enter License Keys.

Select Complete Installation.

SP2013Installation03

During installation, you will get the following page.

SP2013Installation04

When the installation is complete, select “Run the SharePoint Products Configuration Wizard now” checkbox and click Close.

SP2013Installation05

Run the SharePoint Configuration Wizard (Gray Wizard).

SP2013Installation06

Select “Create a new server farm”.

SP2013Installation07

Specify the Configuration Database settings and Database access account.

SP2013Installation08

Specify Farm passphrase. Note down the password at secure location which we will need in future. It is impossible to retrieve the farm passphrase. You can just reset it. The instructions are given here. http://sharepointadam.com/2010/01/21/reset-the-farm-passphrase-in-sharepoint-2010/.

Specify the port number for central administration web application. Avoid using port 8888, because by default fiddler uses the same port and you will need to change that if you need to use fiddler to troubleshoot any issues. http://www.fiddler2.com/fiddler2/

Click next and you will see the configuration settings that will get applied.

SP2013Installation09

Click next and the configuration wizard will run for 2-5 mins.

SP2013Installation10

Known Issue:

If the configuration fails at step 3 with below error message

SP2013Installation11

We need to change the “max degree of parrallelism” of the SQL 2012 Server. The steps are mentioned here. http://msdn.microsoft.com/en-us/library/ms181007(v=sql.105).aspx

Login to the SQL server with SQL service account (sharepointlab\sp_sql_server) and change the “max degree of parallelism” to 1 using following SQL script.

sp_configure ‘show advanced options’, 1;
GO
RECONFIGURE WITH OVERRIDE;
GO
sp_configure ‘max degree of parallelism’, 1;
GO
RECONFIGURE WITH OVERRIDE;
GO

Open the SQL 2012 Management Studio. Open a new SQL query and type/paste above commands.

SP2013Installation12

Execute the query.

Till this point, config wizard has already created “SharePoint_Config” database. We need to delete that and re-run the configuration wizard.

If there are no errors during configuration, you will get the Configuration Successful page.

SP2013Installation13

Clicking finish will launch the Farm Configuration Wizard (White Wizard). Using Farm Configuration Wizard, we can create the service applications. It is recommended to create service applications as and when needed and not to create them using Farm Configuration Wizard.

By default, SharePoint 2013 Configuration wizard (Gray Wizard) creates following Service Applications.

  • Application Discovery and Load Balancer Service Application
  • Security Token Service Application

SP2013Installation14

Following are the screen shots of databases before and after SharePoint 2013 Configuration Wizard.

Databases before SharePoint 2013 Configuration Wizard:

SP2013Installation15

Databases after SharePoint 2013 Configuration Wizard:

SP2013Installation16

At this point you have successfully created the SharePoint 2013 development environment. You can now create the Web Application, create site collections and different service applications. If you are a developer then you can install the Visual Studio 2012.

Posted in SharePoint 2013, SharePoint 2013 Administration | Tagged , , , , | 3 Comments