Removing checkbox from SharePoint view using PowerShell

At times there is a need to remove the selection checkboxes in SharePoint list/library views. The following PowerShell code does that for you $OpenWeb = Get-SPWeb
$OpenList = $OpenWeb.Lists["My Library"]
$OpenView = $OpenList.Views["All Documents"]
$OpenView.TabularView = $false

Show custom error message instead of Web part access denied – SharePoint 2010

Many times while using “ListViewWebPart” you get the following error if the user does not have access to the list/library
Error Web Part Error: Access denied. You do not have permission to perform this action or access this resource”
Though the error is kind of explanatory but is not very user friendly. I have getting demands from lot of customers to replace this error with a custom error message. Let us see how we can achieve this using Jquery
1. Download latest version of Jquery
2. Edit Page where you have added you ListViewWebPart and add a “Content Editor Web part” at the end of the page. Make the web part hidden
3. Add the following JavaScript to the “Content Editor Web Part”

<script type="text/javascript" src="/Shared%20Document/jquery.js"></script>
<script type="text/javascript">
function() {
$('div[errorwebpart="1"]').text('The content of this section is restricted to authorized users only.');

Note: the path for the Jquery should be your path for the Jquery file

Once done you will be able to see the custom message instead of generic Sharepoint message


Create listview webpart to show items inside folders

When you navigate inside a folder inside a document library you will notice that the URL changes. SharePoint makes use of URL Querystring to display data inside folders.

Assume you have document library as “Shared Documents” and you create a folder called as “mydocument” inside it. when you navigate inside the folder the url in your browser should look something like this


As you may see that the SharePoint OOTB list view webpart uses these three parameters (RootFolder,FolderCTID,View) to render the folder contents to you

RootFolder – Root Folder URL
FolderCTID – Folder Content Type ID (optional)
View – Specified View Guid for the Document library

So you need to create a custom list view web part and then set the following three properties to show data inside a specific folder

But there is a catch here. You can set the View for a listview web part but not the “RootFolder” and “FolderCTID” as they are managed internally by sharepoint.Here we will use refelection to set these values and achieve desired results

Code Sample

protected override void CreateChildControls()
        SPSite site = new SPSite("http://{yoursite}");
        SPWeb web = site.OpenWeb();
        SPList list = web.Lists["Shared Documents"];

        // Instantiate the web part
        ListViewWebPart lvwp = new ListViewWebPart();
        lvwp.ListName = list.ID.ToString("B").ToUpper();
        lvwp.ViewGuid = list.Views["SomeView"].ID.ToString("B").ToUpper();
        //Get the rootfolder url here and content type id of folder e.g. "0x012000C5E1253B0EF534479884B846FA62FCFC"
       SPFolder folder = web.GetFolder("/Shared Documents/mydocument");

       SPContentTypeId folderctid = folder.Item.ContentType.Id;

        //set the folder url
       // set the folder content type id ----- Note this is optional and can be skipped 🙂 

      catch (Exception ex)
        Label lbl = new Label();
        lbl.Text = "Error occured: ";
        lbl.Text += ex.Message;

private static void SetPrivateFieldValue(object obj, string fieldName,string val)
  FieldInfo fi = obj.GetType().GetField(fieldName,System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
  fi.SetValue(obj, val);