Pages

Wednesday, April 25, 2012

Removing Columns for Content Types

Creating a new custom content type? Have to inherit from something but you don't want to include all the fields/columns from the parent?

Simple (in most cases). Use the following powershell script to remove (note does not delete the column which doesn't belong to you to delete anyway :))

$ver = $host | select version
if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"}
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

#Attach to the web and content type
$web = Get-SPWeb http://intranet.contoso.com/
$ct = $web.ContentTypes["Content Type"]

#Insert name of column to remove from Content Type
$columnName = "Comments"

#Get link to the columnn from the web
$spFieldLink = $ct.FieldLinks[$columnName]
#Recently I tried to use this script and this line failed, I replaced it with the one above and its fine.
#$spFieldLink = New-Object Microsoft.SharePoint.SPFieldLink($web.Fields[$columnName])

#Remove the column from the content type and update
$ct.FieldLinks.Delete($spFieldLink.Id)
$ct.Update()

#Test that the column was successfully removed from the Content Type
if ($ct.Fields[$columnName])
{
    Write-Host "$columnName was not removed"
}
else
{
    Write-Host "$columnName was removed"
}

Note: Only issue I have found so far is that I still cannot remove all fields that I want removed. In my case I wanted to remove the "Comments" field from a content type but for some reason it won't remove.

EDIT: Figured out how to delete/remove the Comments field from my content type.
First make it hidden (you can do this through the UI or in a script) then the above script can be used to remove it. Weird by it works

SharePoint Permissions Tip: Leave the Style Resource Readers group alone

I've spent quite a bit of time tracking down issues that all relate to permissions for the Style Resource Readers group. My number 1 permissions tip: Don't change anything to do with this group!!!

There are several ramifications when this group's permissions change, users may start reporting that they have 'Access Denied' errors trying to edit or create pages. Or if you have a structure where you want users to only be able to access a sub site and you don't give any permissions to the Root site, then they will get 'Access Denied' everywhere.

Create / Edit publishing pages

What that meant was, because SharePoint was trying to render the masterpage and page layout on either the page they wanted to edit or a new page, it couldn't because they didn't have access to them, regardless of the fact they had access to the page library.

It's a weird error to try and track down because the user will report that they still have access to create/edit items in a list, they can still see Site Settings, they still seem to have enough privelages to do it, but get an outright 'access denied' error.

Access Denied to sub sites

I had created a group just for a sub site to have view only permissions however users were reporting that they got 'Access Denied' messages. Again it turns out that although the Style Resource Readers group existing in the Root site with all authenticated users it didn't have any permissions on the Style Library document library itself, hence why access didn't work in the sub site.
Just ensure that the Master Page Gallery (Style Library) has the Style Resource Readers group as having restricted read permission on the library.

SharePoint 2010 Web Services and Anonymous Access

Looks like SharePoint 2010 still has issues with Anonymous Access and its web services.
There are a fwe articles out there pointing at this issue in 2007 but I'm afraid its no better in 2010 (SharePoint 15?).

This article (Trinkit HQ) is short and sweet, and gets right to the point. Basically if your Web Application has Anonymous Access turned on, you will experience the 'Attempted to perform an unauthorized operation' error.

There are a few ways to deal with it, extend another web app, muck around with IIS (not recommended) but the bottom line is:
Anonymous Access = No Web Services

Thursday, March 15, 2012

Customising RichTextEditor's Styles and Markup Styles Menu Items

OK, there are a few articles around discussing how to do this, this post by Marc seems to be the definitive article about what, where, how and why but I felt like writing a simplified version for myself.
So here goes...

What are we talking about?
First, I'll try and give my own spin on what the Styles and Markup Styles are and what they affect.
Below is the definition given by many when describing what the differences are between the two, my interpretation of these are given in italics.

Markup Styles
  • Nest the text and its HTML tag within the html tag specified in the style if the tag to nest is a span element. What a mouthful, ok I think it means, if the text you are trying to apply a Markup Style to is a span element, then the text and its surrounding tag (probably div p or h1 etc) will get 'nested' inside the tag specified by the css class you create.
  • Replace the current tag if is is not a span element. If the text is not in a span, then the current tags (again probably div, p etc) will be replaced with the tag in the css class.
  • Remove all the styles for the children elements. This is easy, removes all the children styles so that the selected text will all be rendered using the specified css class.
  • Remove the html tag if the same style is applied a second time (this is a way of removing a Markup style for an end-user). Simple, removes the style.
Styles
  • Nest the text in a span tag with the style class if the text is not already inside an HTML tag.
  • Just add the class to the current HTML tag if this tag is not a span tag.
  • Replace the class of the HTML tag if this tag is a span tag.
  • Remove the html span tag if the same style is applied a second time (this is a way of removing a Style for an end-user) Simple, removes the style.

Clear as mud, good. Now, both these 'styles' are used in the Rich Text Editors of both Wiki Pages and Publishing Pages and by default, the CSS classes live in \14\template\layouts\1036\styles\themable\corev4.css stylesheet.
Right, well how do we change it?
So we now have an idea of what the ribbon controls do, how do we add to or change them?

Syntax
OK, now for the cool way in which this stuff gets pulled together. All styles conform to a naming convention. This convention is then used by the RTE on the client side to build the ribbon control. So all you need to do is follow the convention and you can add a new class/style to the ribbon, easy.

.ms-rteStyle-xxxxx - for styles

.ms-rteElement-xxxxx - for markup styles

Simple? Just add the name of the class you want to create where the x's are and there you go, well almost. Inside the class definition, you need to add

-ms-name:"xxxxx";

Where again, you replace the x's with the name you want to appear in the ribbon control. So if I wanted to add a style like Heading 5, I could do the following:

.ms-rteStyle-H5
{
   -ms-name:"Heading 5";
   FONT-SIZE:14pt;
   FONT-WEIGHT:normal;
}

You get the picture, sky's the limit as to what you can do with your text. Either trawl through the corev4.css or just look at the styles applied to text after you change a markup style using developer tools (F12 in IE).

Well, sounds like we have all the information about these styles that we need so we can pretty much do anything right? Not quite. Removing a style is tricky. Adding and Changing is simple, because its just css. There are some ways to remove styles including custom masterpages, jQuery and custom page layouts etc so there is a way around it. I won't go into that in this article, use bingle.

Solution Management
So now you know what to change, where do you change it? What's best practice for lifecycle management of this solution? Depends :)

Testing / Debugging
Simple, wack the css into a file, upload it to the Styles Library and reference it using the HTML Form Web Part on the page you want to test. Simple, no code changes to pages, solutions etc. And you could get away with doing this in production if it was only on 1 or 2 pages, but having this as a reuseable solution just won't cut it.

MasterPage
In my opinion, the best way to do this is by putting a CSS Registration reference into a master page pointing to a specific css file you want to setup in the Style Library. This way, if you don't want to use any custom styles, you just don't have the css file in the Style Library, but if you do, then you can just edit the file. The added benefit of this is that you can have different files for different Site Collections. Just add the line below to your masterpage, up near the top, there is probably already similar references.

{SharePoint:CssRegistration name="{% $SPUrl:~sitecollection/Style Library/~language/MarkupStyles.css %}" After="corev4.css" runat="server"/}
(don't forget to replace the curly braces with greater than/less than symbols, and change the path where relevant)

Other Options
There are other options available where you are either editing the core files, editing existing pages or page layouts etc. but I wouldn't really go near them.

Removal of the OOTB styles is difficult. This can be done either through JavaScript or by adding server-side code to remove references to corev4.css etc, see Marc's article near the bottom for these.

If you are going to go down the path of modifying a Master Page, then perhaps you can insert your JavaScript in the master page and do some tricky stuff there but that is out of my league :)

SharePoint Search Web Services and anonymous access

Recently had to debug an issue with a 3rd Party app using the /_vti_bin/search.asmx web service which, at the time, stopped working with 'no changes' to the environment. We were receiving the SoapException: 'Server was unable to process request ... Unauthorized Operation'.

This turned out to be not quite the truth and infact Anonymous Access was enabled on the Web Application for use by a monitoring tool. The Farm configuration doesn't use Kerberos (jury is still out on whether Kerberos is needed in this situation anyway), just Ntlm and it seems that once a successful connection is made to another SharePoint web service (in this case /_vti_bin/lists.asmx) then a subsequent call to the search service works.

We did a bit of packet sniffing as well and it looks like the search service trys to authenticate differently than the other web services. Not sure why this is the case. I need to understand more about how Search works.

Here's the post on TechNet.

Moral of the story is to check, and double check the environment before spending time going down rabbit holes. Statements like 'it was working, then it stopped...with no change in the environment' just don't add up.

Thursday, January 5, 2012

Issue with DNS using VirtualBox and the SharePoint 2010 VHD

After many hours of trying and reading I finally stumbled across an article that described my problem and solution.
Thanks very much Edward http://microsoftdevguy.blogspot.com/2011/05/sharepoint-demo-image-gets-error.html
It seems that trying to follow the MS Install guide didn't quite work and after you successfully run the image, the only site you can hit is CA. After following Edwards article and just using a Bridged Adapter and an available IP address in the Host networks range, then modifying the Guest adapter and DNS entries, viola! Magic!