Anonymous Users accessing a SharePoint List – An error has occurred. Access denied. You do not have permission to perform this action or access this resource

Right then. A custom web part is happily accessing a list using CSOM on a public facing SharePoint site. While setting up a copy of that environment I found that the web part began complaining with the error, “An error has occurred. Access denied. You do not have permission to perform this action or access this resource.” Now I’ve seen this before and recalled that there is a restriction by default when reading list items as an anonymous user when using the method getItems(camlQuery). That restriction can be removed through a few SharePoint PowerShell commands but there is additional step after allowing the method to be called. That is to check that the “Client Object Model Permission Requirement” is disabled. Let’s do this…

  1. Get a reference to the Web Application
  2. Check the restrictions on your web app and look for GetItems method
  3. Remove GetItems method from the restricted MethodsNames
  4. Update the Web Application
  5. Check again to ensure the method was removed.

Here are the PowerShell Commands for each step:

$webapp = Get-SPWebApplication -Identity

At this point, The GetItems method has been successfully unlisted from the restricted methods list. However, you still may be getting the access denied error. That could be due to a Permissions Setting for Anonymous Users.

You can update permission settings at the Web Application level or at the Site Level. For the Web Application level, let’s go back to Central Admin -> Application Management -> Manage Web Applications and select your Web App. Open Authentication Providers and select Default. Scroll down to “Client Object Model Permission Requirement.”  As long as you agree not requiring “Use Remote Interfaces permission” go ahead and disable the permission.

To update the Site permissions, go to Site Settings and Site permissions. Look at the Anonymous Access in the Ribbon. Make sure that Require Use Remote Interfaces permission is disabled (see screenshot). Now anonymous users will be able to see data via the web part without an access denied error.

Leave a comment

SharePoint Rich Text Editor List Field strips out Target Attribute

In a custom SharePoint list definition that contains a field type which is a RTE (Rich Text Editor), I found that items added to the list would allow for anchor tags, but the “Target” attribute was stripped off when the HTML markup was saved. In the MSDN definition for the Field Element (List) I found an answer to this problem

The first step is to add the IsolateStyles property and set to false. The second step is to set the RichTextMode to “FullHtml.” After these to settings and updating the list, I was able to add the “target” attribute to an Anchor tag in the HTML markup for a list item.

In the end, this is what the field definition looks like in the list schema.xml file:

<Field ID=”{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}” Type=”HTML” DisplayName=”Description” NumLines=”4″ RichText=”TRUE” RichTextMode=”FullHtml” IsolateStyles=”FALSE” Name=”AlertDescription” RestrictedMode=”FALSE”/>

Leave a comment

When did I build that project in Visual Studio?

Have you ever started a build in Visual Studio and went off to do some other darn important things?  Then when you come back twenty-seven minutes later, you look at the Output Window and say… “Did I build that yet or is that from an hour ago?”  Well, I do. It’s not easy getting older. But, there’s a simple command you can put in the “VS Project Properties – Build Events – Post-build event command line” that will output the time the build finished. “Time /T” Pretty ingenious, no? Yeah, not really, but it works. I even have some screen shots for those who can’t read! Cool slide-show mode too.

This slideshow requires JavaScript.

Happy Turkey Day!

Leave a comment

Making Your Site Collection Read Only

This is one of those blog entries just to remind myself how to do this rather than Google it. It’s pretty simple.

Go to Central Admin –> Application Management


Under Site Collections, click on “Configure quotes and locks”


Under Site Lock Information, select the Read Only (blocks additions, updates, and deletions)


That’s it, you’re done. Now when a user will see something like the following from the Site Actions drop down menu. A subset of the complete site actions for a non read only Site Collection:



Leave a comment

Using the HTML Form Web Part to POST a form outside SharePoint (and dealing with WPQ)

To simplify the form building for users who know HTML, we decided to use the out of the box HTML Form Web Part.  That web part has some limitations.  Specifically, you cannot add or embed another <form> tag to the source code. Without the ability to specify the OnSubmit for the form, there has to be another way to indicate the method and action on the submit of the form.

After searching Google, I can upon this CodePlex project: “SharePoint form submit in content editor web part” and subsequent version 2, which handles the parameters much nicer.

I included the javascript file in my feature so that users could reference it from their HTML.  In the end, the form looks something like this:

<script type="text/javascript" src="/_layouts/Sohema/jquery.SharePointFormSubmit.js"></script>

<div id="divIdForm" class="mode_edit balloon">
    <input type=hidden name="myId" value="SOHEMA">
    <input type=hidden name="retURL" value="">

    <label for="first_name">First Name</label><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
    <label for="last_name">Last Name</label><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
    <label for="email">Email</label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br>

    I think this is so:<select id="543645" name="llp" title="I think this is so">
    <option value="">-None-</option>
    <option value="cool">Cool</option>
    <option value="radical">Radical</option>
    <option value="meatball">Meatball</option>

    <button id="idButton" type="button" class="btn_capsule btn_120 gn align_right" onclick="jQuery().SharePointFormSubmit(
              'frmAction': '',

There was a small problem with the HTML.  SharePoint handles multiple web parts on a page by prepending the field names with “WPQ#”, where # is some number.  This is fine until the service you are posting to expects the field names to be a specific name. By modifying the jquery, I update the field names using these lines of code in the file jquery.SharePointFormSubmit.js:

var wpPrefix = arr[‘wpPrefix’];


newName = $(this).attr(‘name’).replace(wpPrefix, "");

e.attr(‘name’, newName);

The wpPrefix is the prefix of the web part that is set by SharePoint on that particular page.  This can be found by viewing the page source of the HTML Form Web Part.  In my case, it was “WPQ7.”

The field names are updated on the submit. It is a good idea to view what the form is passing using some HTTP tools.  My favorite is FireFox with the Firebug and Live HTTP Headers Add-Ons.

And there you have it.


Google Search using Page Viewer Web Part on SharePoint 2010

If you ever tried adding Google Search code that will search your site to a SharePoint page using the HTML Form web part, you might get an error like this:

Unexpected System.NullReferenceException: Object reference not set to an instance of an object.   at Microsoft.SharePoint.WebPartPages.WikiPageWebPartSaver.SaveWebPartsInRichText(SPWebPartManager wpmgr)

A simple way to add the Google Search for your site is to use the Page Viewer Web Part and reference an HTML file with the Google Search form code:

 <!-- Search Google --> 
<font color="#006633" size="+1" face="Times New Roman">Search</font> 
<FORM action= method=GET target="_blank"> 
<TABLE bgcolor=#FFFFFF cellspacing=0 border=0><tr valign=middle><td><!--mstheme--><font face="Times New Roman"> 
<A HREF= > 
<IMG SRC="" border=0 ALT=Google width="128" height="53"></A> <!--mstheme--></font></td> 
<td><!--mstheme--><font face="Times New Roman"> 
<INPUT TYPE=text name=q size=31 maxlength=255 value=""> 
<INPUT type=submit name=sa VALUE="Google Search" > 
<input type=hidden name=hq value="" > 
<font face=arial,sans-serif size=-1><br><input type=hidden name=sitesearch value="" checked> 
<!--mstheme--><font face="Times New Roman">    
<!-- Search Google --> 

Add the file to the sub folder under LAYOUTS:  \Web Server Extensions\14\TEMPLATE\LAYOUTS\Custom\google.html

Then, add a Page Viewer Web Part (Under Media and Content) to a page and set the Web Page property to http://ServerName/_layouts/custom/google.html


Note: You may have to allow the search to open in a new window.

Leave a comment

SharePoint 2010 Architectures Overview Article

When someone asks, “What is SharePoint?” it is difficult to give a comprehensive answer, but this excellent article about SharePoint on MSDN does a pretty good job.

Leave a comment

Change the Sort order for ContentByQueryWebPart (CQWP)

In a custom version of the ContentByQueryWebPart, the items that were displayed from a list were not being sorted in any meaningful way.  The default sort is the created date.  To fix this, there are a few properties that needed to be added in the implementation using the object model approach.  The properties are “SortBy”, “SortDirection”, and “SortByFieldType.”  Here is how this is done in code and note that the “SortBy” field is not the title of the field name but the item ID:

public class CoolNav : ContentByQueryWebPart
            static string listGuid = String.Empty;
            static string url = String.Empty;
            static string itemStyle = "LinkList";
            static SPList list; 

            public CoolNav() : base()
                if (listGuid == String.Empty)
                    listGuid = SPContext.Current.Site.RootWeb.Lists["Cool Navigation"].ID.ToString();
                    list = SPContext.Current.Site.RootWeb.Lists["Cool Navigation"];

                if (url == String.Empty)
                    url = SPContext.Current.Site.ServerRelativeUrl;
            protected override void OnLoad(EventArgs e)
                this.ListGuid = listGuid;
                this.WebUrl = url;
                // Sort Properties
                this.SortBy = list.Fields["Order"].Id.ToString();
                this.SortByDirection = SortDirection.Asc;
                this.SortByFieldType = "Number";
                String ServerURL = SPContext.Current.Site.ServerRelativeUrl;
                //Fix the URL Path
                if (!ServerURL.EndsWith(@"/"))
                    ServerURL += @"/";
                this.MainXslLink = ServerURL + @"Style Library/XSL Style Sheets/CoolNav.xsl";
                this.ItemXslLink = ServerURL + @"Style Library/XSL Style Sheets/CoolNav_ItemStyle.xsl";
                this.ItemStyle = itemStyle;
                this.CommonViewFields = "URL,text";

Leave a comment

How to verify that a SharePoint List exists

Two ways to do check if a SharePoint list exists (that I know of)…

1. Put it in a Try/Catch block

        /// <summary>
        /// Utility function to check if a list exists
        /// </summary>
        private static bool DoesListExist(SPWeb web, string listName)
                SPList list = web.Lists[listName];
                return false;
            return true;

2. Use the TryGetList function from SPListCollection:

if (SPContext.Current.Site.RootWeb.Lists.TryGetList(ListName) != null)


Leave a comment

PowerShell Script tips: Writing to a log file and checking for a PSSnapin

A couple of tips that I gleaned while writing PowerShell scripts:

    1. To write output to a file, use the “Write-Output” command like this: “Write-Output $log_text” and when executing the script, pipe the output to a file like so:

PS C:\> psscripts\coolscript.ps1 | Out-File C:\psscripts\ps.log

2. Sometimes I run scripts from within the Windows PowerShell Integrated Scripting Environment (ISE) and other times from the SharePoint 2010 Management Shell.  To avoid the error of re-adding the SharePoint snapin, I use this code to check if it has already been loaded:

$powershellSnapin = “Microsoft.Sharepoint.Powershell”
if ((Get-PSSnapin -Name $powershellSnapin -ErrorAction SilentlyContinue) -eq $null )
Add-PsSnapin $powershellSnapin

Leave a comment