Posts Tagged ‘ SharePoint 2010 ’

Custom Rich Text Editor Styles in SharePoint 2010

A common request to have in SharePoint 2010, especially externally facing installations, is to have custom Styles available in the menu.

Thankfully, SharePoint 2010 makes this extremely easy. The key is the prefix attached to your styles. SharePoint will interpret any style beginning with ms-rteElement-[custom name] as a markup style and it will interpret anything starting with ms-rteStyle-[custom name] as a Style. However, you are able to change this prefix, but we’ll start out by creating some new styles using the default ‘ms-rte’

First, the differences between the two:

Markup Styles (ms-rteElement):

  • Will wrap the currently selected area in the specified tag (See below)
  • Applied style to newly created tag

Styles (ms-rteStyle):

  • Applies your custom class to the currently selected element
  • Will not add additional markup

Getting Started

Now that we’ve discussed the differences between them, lets talk about how to implement them. To start, make sure you have a stylesheet already linked on your SharePoint master page. Once that’s ready, follow the steps below.

Continue reading

SharePoint 2010 Client Object Model – ECMA Script Get List Fields

I was working on a project that required me to dynamically build a grid based on a SharePoint list using client side JavaScript and naturally, I needed a way of retrieving the fields (columns) of the list. Some research revealed the best way to do this use the SharePoint client object model.

Before we write any code lets make sure that everything we’ll need is ready when our code executes. So, lets wait for the sp.js script to load before we execute our function. We can do that with this snippet of code:

function getFields() {
 // waiting until the core.js is loaded
 ExecuteOrDelayUntilScriptLoaded(retrieveAllFields, 'sp.js');

Now that we’re sure our code will work, lets write it. First, we’ll need to build the client context query in our retrieveAllFields function.

function retrieveAllListsAllFields() {
 // Getting List Title
 var listTitle = 'TestList';
// Building environment
 var clientContext = new SP.ClientContext.get_current();
 var oWebsite = clientContext.get_web();
// Getting all Fields in default view
 this.list = oWebsite.get_lists().getByTitle(listTitle);
 var defaulViewGUID = '{YOUR GUID}';
 var defaultview = list.getView(defaulViewGUID); // Default GUID
 this.listFields = defaultview.get_viewFields();
// Getting Detailed Information on the Fields
 var collList = oWebsite.get_lists();
 this.listInfoArray = clientContext.loadQuery(collList,
// Executing Query
 clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),
 Function.createDelegate(this, this.onQueryFailed));

Now that we have our query ready to go. Let’s create our logic to process our list fields.

function onQuerySucceeded() {
// Setting Site URL
for (var i = 0; i < this.listInfoArray.length; i++) {
 var oList = this.listInfoArray[i];
 var collField = oList.get_fields(); // Getting All Fields From the List
 var listTitle = oList.get_title()
 if (listTitle == this.list.get_title()) {
 var fieldEnumerator = collField.getEnumerator();
 var textInfo = "";
 // Looping through all fields 
   while (fieldEnumerator.moveNext()) {
     var oField = fieldEnumerator.get_current();
     var internalName = oField.get_internalName();

 // Checking to see if the field is in the current view
     var viewFieldEnumerator = listFields.getEnumerator();
     while (viewFieldEnumerator.moveNext()) {
       var currentFieldTitle = viewFieldEnumerator.get_current(); // Getting Title
 var itemTitle = oField.get_title();
       var type = oField.get_fieldTypeKind();
       textInfo = listTitle + " - " + currentFieldTitle + " " + itemTitle + " " + type + " " + internalName;
 // Adding Info

And you’re done! You’ll notice that my code gets the fields in the current view and compares them to the fields returned in the list query.  This way, you’re not getting back every single field in the list schema (including the ugly hidden ones).

As always, if you spot and error or have a suggestion for an improvement let me know and I’ll update my post.


jQuery CAML Query – lists.asmx Web Service

So, recently I’ve embarked on a project to create a client side jQuery grid. To do this, I started out by creating a simple table from list data return from a CAML query to the list.asmx web service.

To get me started, I used Jan Tielen’s blog post Here. His example works perfectly accept you’ll need to modify one line of code to make it fully cross-browser compatible.

Change this:

$(xData.responseXML).find(“z\\:row”).each(function() {

to this:

$(xData.responseXML).find(“z\\:row, row”).each(function() {
Continue reading

InfoPath 2010 – Validating the Attachments Field

InfoPath 2010 has its ups and downs. For the most part it makes things extremely easy. However, you’ll still run into the occasional roadblock while working with InfoPath forms.

I recently ran into one such roadblock. The issue was being able to apply validation rules to the attachments field. To my surprise, InfoPath does not let you select the Attachments field to apply rules, making it a challenge apply validation on attachment fields. Also, if you go into the advanced view and select the repeating ‘:attachmentURL’ field inside of the Attachments group and apply formatting to that field it just doesn’t work.

So, I had to come up with a custom solution. Now, given one of the major advantages of using InfoPath in the first place is not having to use any code behind, I didn’t want to have to add custom code to my form.

My solution involves 3 steps:

1.) Create a field in addition to the attachments field. In my case, I called the field I created Attachment Validation.

2.) Drop your field onto the form and remove the borders and background. Then set the default text to ‘Attachments:’

InfoPath 2010 Attachments Field Validation

3.) Finally, lets apply some validation to this field. Right click the field on your form and select Rules > Manage Rules.

In my case, I needed to make sure there was at least one attachement. So, I counted the :attachmentURL instances and checked if there were more than 0. To do this, I used a custom expression:

Now with all of that complete you will have a separate field that validates the attachments field and if there are no attachments, the text in the left hand column will be surrounded in the standard red dashed border.

InfoPath 2010 Validation on Attachments Field


To get to the ‘:attachmentsURL’ field you need to create the validation make sure you go into Advanced View of the fields.

InfoPath 2010 Attachments :attachmentURL field advanced view

Converting an InfoPath Filler Form to a Web Based InfoPath Form

So, I’ve been working on an InfoPath form that was passed down to me and originally created as a Filler form. I finally completed it and needed to publish it, but there was a problem; its a filler form not a web based form. So, I had to reconfigure the form to work in a web browser and not try to launch in InfoPath filler.

The first step was to change the form to a Web Browser Form by going to the File tab > Form Options

InfoPath Options Menu

Next, you’ll want to go into the Compatibility section of the Form Options menu
Continue reading

SPMetal with Anonymous Access

So, I recently ran into a problem with using SPMetal with anonymous access. When Anonymous users access a web part that runs LINQ queries, they’ll get prompted for credentials in SharePoint 2010. The problem is actually related to the way the LINQ code works. It uses the default SPContext.Current to get the site objects. This becomes a problem when you need to run a piece of code with elevated permissions because without rebuilding the SPContext.Current, you’re still using the default permissions. With the default permissions, as an anonymous user, you will not have enough access to make calls using LINQ and as a result, you’ll be prompted to log in.

This blog had an okay solution:

Use the HttpContext object to force all SP objects to be created again. When this happens within the RunWithElevatedPrivileges method, the SPContext is recreated with this higher level of priveleges.

This code has its problems though.

Continue reading

SharePoint 2010 CSS Chart

I found a fantastic resource for someone who is branding SharePoint 2010 or implementing their own custom design.

It is a detailed chart on what CSS classes are used in SharePoint 2010, where they are used, and a graphic outlining the areas they effect. The author even includes the CSS tags that are used so you can easily copy & paste them into your Style Sheets.

I would recommend taking a look at this if you’re planning on stylizing SharePoint 2010. I wish I would have found it earlier!

Thanks go out to the SharePoint Experience for putting the list together.