Posts Tagged ‘SharePoint Designer 2010’

Current user in SharePoint Designer

When a SharePoint 2010 site is opened in SharePoint Designer 2010 the user logged in to the site is usually the user logged in to the machine you are working on. Sometimes you aren’t automatically logged in and you have to enter your credentials to access the site you are trying to open.

In some cases it is desirable to log in as a different user to test permissions, for example.

SharePoint Designer displays a very small icon in the lower-left corner of the screen. When hovering the mouse over it, the currently logged in user is visible:

Clicking this icon gives you the possibility to log in as another user.

Locking down SharePoint Designer 2010

Back in MOSS 2007 the onet.xml file had to be edited to disable editing in SharePoint Designer. This option was a setting for everybody and all aspects at the whole site collection, no exceptions here.

Fortunately this is much better in SharePoint 2010. Below the Site Collection Administration settings the option SharePoint Designer Settings is listed (Site Actions; Site Settings; Site Collection Administration; SharePoint Designer Settings).

At the screen showing now the first option is: Enable SharePoint Designer.

To test this option a permission level has been set up by copying the default Read permission level and add an additional Site Permission to let the user edit in SPD when this is enabled: Add and Customize Pages. Based on this permission level a group has been created and the user is placed in this group.

When this user is logged on to the SharePoint site the Site Actions menu is shown and the option Edit in SharePoint Designer is present.

The option Enable SharePoint Designer is checked:
When selecting this option SharePoint Designer is opened and editing can begin.

The option Enable SharePoint Designer is unchecked:
When selecting this option SharePoint Designer is opened and editing can not begin:

At both scenario’s a site collection owner can still edit the site with SharePoint Designer.

Great option and a lot easier than achieving the same behaviour in MOSS 2007.

Besides turning off all the editing possibilities, a selection of the possibilities can be made by the other three options displayed at the SharePoint Designer Settings screen:

  1. Enable Detaching Pages from the Site Definition: Enabling this option let’s users detach the pages, the page will then be stored in the database and not on the file system anymore.
  2. Enable Customizing Master Pages and Page Layouts: Enabling this the site’s look and feel for example can be different at some time (and from time to time when another user doesn’t like the new look and feel…)!
  3. Enable Managing of the Web Site Url Structure: This option allows (when enabled) viewing and managing the hidden URL structure, such as the _layouts and _catalogs folder.

Enabling or disabling some or all SPD editing possibilities is in my opinion no different with other SharePoint options: it depends!

Please make sure you are aware of the consequences when users are able to edit the site in SPD. If you can live with the items to fix when it’s all gone bad, it’s ok. Otherwise restrict the user so they can’t make a mess of the site.

BCS model – a simple editable model

Let’s adjust the previous model to enable adding new items and edit existing ones. 

Open the previous project and open the design view of the model (.bdcm). In the BDC Method Details window select ‘Add a method’ and ‘Create Creator Method’. Two parameters are created, one for input, one as return parameter. Check the type names of both Type Descriptors. Both have to be set to the Customer entity. Probably they are set correctly already, because of the previous ReadList and ReadItem methods. Open the BDC Explorer and make sure the other type descriptors (the ones that make up a Customer) are present at the input and return parameter. Probably they also are there already.
Check the properties of the type descriptors of the input parameter ‘NewCustomer’. The property CreatorField is set to True here. With this parameter you can control the fields displayed on the new form. Since our CustomerId is an auto increment field, delete this type descriptor from the input parameter.
That’s it for the configuration, the only thing left is to update the code at the CustomerService class. As in the previous post I use Linq to Sql, an example:

        public static Customer CreateCustomer(Customer newCustomer)
        {
            using (LinqToSQLClassCustomerDataContext db = new LinqToSQLClassCustomerDataContext(CONNECTION_STRING))
            {
                CustomerBasic newItem = new CustomerBasic();
                newItem.CustomerName = newCustomer.CustomerName;
                newItem.CustomerCity = newCustomer.CustomerCity;
                db.CustomerBasics.InsertOnSubmit(newItem);
                db.SubmitChanges(); 

                Customer returnCust = new Customer
                {
                    CustomerId = newCustomer.CustomerId
                };

                return returnCust;
            }
        }

Deploy the solution and check out the list created on the previous version of this solution. The list seems fine and at the List Tools tab, Items, the New Item button is enabled. Select this button.
When expecting the new form, a Runtime Error occurs.
Open SharePoint Designer and select the list. In the next screen several items of the list are displayed, e.g. Settings, Views and… Forms! As you can see at the picture below there is no NewForm, that’s why the error occurs.
 

And checking the logfile:
SPException thrown: Message: Unable to find the default new form for list
Says the same, no New Form present. 

To get a full functioning list, create a new list based on the External Content Type and the NewForm is present:
  

Ofcourse SharePoint Designer can help you out without creating a new list by selecting NewForm at the Forms section:

When selecting ‘New Item’ in the browser a new Customer can be added.
    

The updater method is just as simple.
In the BDC Method Details window select ‘Add a method’ and ‘Create Updater Method’. One input parameter is created ‘customer’. Check the type name of the Type Descriptor. This has to be set to the Customer entity. Probably it is set correctly already, because of the previous defined methods. Open the BDC Explorer and make sure the other type descriptors (the ones that make up a Customer) are present at the input parameter. Probably they also are there already. Set the Read Only property of the CustomerId type descriptor to false and leave the Updater Field property set to True.    

Now update the code for the updated method to actually update the Customer.

        public static void UpdateCustomer(Customer customer)
        {
            using (LinqToSQLClassCustomerDataContext db = new LinqToSQLClassCustomerDataContext(CONNECTION_STRING))
            {
                CustomerBasic updateItem = (from c in db.CustomerBasics
                                            where c.CustomerId == customer.CustomerId
                                            select c).FirstOrDefault();
                updateItem.CustomerName = customer.CustomerName;
                updateItem.CustomerCity = customer.CustomerCity;
                db.SubmitChanges();
            }
        }

 

Deploy the solution and take a look at the list created with the previous version of the solution. Same story: Runtime Error; Edit Form not present. SharePoint Designer to the rescue: create a new Edit Form and voila!

jQuery SPServices and autocomplete

On Codeplex the SPServices library is available. This is a jQuery library for SharePoint Web Services.
One of the functions available in the library is the SPAutoComplete:
http://spservices.codeplex.com/wikipage?title=%24%28%29.SPServices.SPAutocomplete  

The SPAutocomplete lets you provide values for a Single line of text column from values in a SharePoint list. The function is highly configurable and can enhance the user experience with forms.  

To use this function you have to put it on a new item form. On one of the fields of this new item form the SPAutoComplete can be implemented and used.  

To make this work, create a new blank webpart page. Open the page in SharePoint Designer and insert a dataview on the page. At the Data Source Library select the list you want to create a new item form for and select Show Data. Select the desired fields to show on the new item form and select Insert Selected Fields as … New Item Form. Save the page and edit the page in the browser.  

Imagine:
I have a list called Customers with a Title column with the name of the customer. In another list I need these names also but I want to suggest the user who adds a new item which customers we already have and how these are spelled.  

Let’s proceed.
Edit the page in the browser and add a Content Editor Webpart, modify the webpart and show the Source Editor to add some code.

<script type="text/javascript" src="../ICTLibrary/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../ICTLibrary/jquery.SPServices-0.5.4.min.js"></script>
 

<script type="text/javascript">
    $(document).ready(function() {
        $().SPServices.SPAutocomplete({
            sourceList: "Customers",
            sourceColumn: "Title",
            columnName: "CustomerName",
            numChars: 2,
            ignoreCase: true,
            slideDownSpeed: 100,
            debug: true
        });
    });
</script>

For all available options to set please take a look at the link provided earlier, but for the important ones here.
sourceList: the list to get the suggestions from
sourceColumn: the static column name to get the suggestions from
columnName: the displayname of the field in the new item form
You can hide the content editor webpart so you only see the new item form. Go ahead and type the first letters of a customername.

Ofcourse you want to use the autocomplete function on other pages or in other webparts and not only on a new item form.
For this purpose you can use the jQuery UI plugin (http://docs.jquery.com/UI/Autocomplete, implemented in release 1.8) in combination with the SPServices library.
With the SPServices library the items can be pulled out of the desired list and column and with the auto complete function of the jQuery UI the source can be set to the values to show.
To get the desired data from the list:

            $().SPServices({
                operation: "GetListItems",
                async: false,
                listName: "Customers",
                CAMLViewFields: '<ViewFields><FieldRef/></ViewFields>',
                CAMLQuery: '<Query><OrderBy><FieldRef Name=\'Title\' Ascending=\'True\' /></OrderBy></Query>',
                completefunc: function(xData, Status) {
                    $(xData.responseXML).find("[nodeName= z:row]").each(function() {
                        itemSource[k] = $(this).attr('ows_Title');
                        k = k + 1;
                    });
                }
            });

  

And use the gathered data in the input field at the page:

            $("input#autocompletebox").autocomplete({
                source: itemSource,
                minLength: 2
            });

Where ‘autocompletebox’ is the id of the input control:

<input id="autocompletebox" />

  

And the output of this all in the browser:

SharePoint 2010

 

September 2009 – heden

SharePoint 2010 consultant/developer

 

Buiten MOSS 2007 is Anita ook op SharePoint 2010 gebied zeer gedreven. Vanaf december 2009 is ze actief bezig met allerlei aspecten van SharePoint 2010 en heeft veel evenementen bijgewoond op SharePoint 2010 gebied waaronder Microsoft SharePoint Connections (2 dagen) in Amsterdam en SharePoint 2010 Evolution Conference (3 dagen) in Londen.

Ter voorbereiding op het examen voor developers van SharePoint 2010 heeft Anita de nieuwe onderdelen van SharePoint 2010 uitvoerig bestudeerd en zelf uitgeprobeerd middels het schrijven van code (C#). Specifieke SharePoint 2010 onderdelen welke aan de orde zijn geweest zijn sandboxed solutions, full-trust proxies, BCS, workflows, web analytics, custom rating icons, dialogs, ribbon customizations (ook contextueel), client object model, LINQ to SharePoint en taxonomy (term store). 

SharePoint 2010, Microsoft Office SharePoint Designer 2010, Visual Studio 2010, jQuery.

Customize rating icons for SharePoint 2010

In SharePoint 2010 the rating icons are default displayed as stars: 
 
Of course these can be changed: with SharePoint Designer, but better with a feature.
There are four images used to display the ratings:
  • 2 images for displaying rating:
    ratings.png

    ratingsrtl.png
  • 2 images for hovering/selecting rating (enlarged):
    ratingsempty.png
    ratingsnew.png

You can find these images in the 14 hive, images folder.
Make your custom icons (16×16), I prefer (the free) Paint.NET program. Just open the original icons, save them with another name and make your own of them.

How to change these images by SharePoint Designer

Open the site in SharePoint Designer.
Select Site Options in the ribbon:
 
 In the Tab parameters you can find the locations of the images by name value pairs. Here you can change the images to your own ones. Recycle application pool to see the changes.

How to change these images by a feature

Create an empty SharePoint 2010 project with Visual Studio 2010 and add a site collection scoped feature.
Add a SharePoint Images Mapped folder and add your images to this folder. Note: Visual Studio adds a subfolder with the name of your project to your and SharePoint’s images are not messed up, nice!

Add an event receiver to your feature to set the properties of the images.
Uncomment the FeatureActivated method and add code:
SPSite site = properties.Feature.Parent as SPSite;
SPWeb web = site.RootWeb;
//preserver original ones
web.AllProperties["ratings_imagestripurl_original"] = web.AllProperties["ratings_imagestripurl"];
web.AllProperties["ratings_newratingiconurl_original"] = web.AllProperties["ratings_newratingiconurl"];
web.AllProperties["ratings_emptyiconurl_original"] = web.AllProperties["ratings_emptyiconurl"];
//set new ones
web.AllProperties["ratings_imagestripurl"] = “_layouts/images/ITIdea.CustomRatings/RatingsFC.png”;
web.AllProperties["ratings_newratingiconurl"] = “_layouts/images/ITIdea.CustomRatings/RatingsNewFC.png”;
web.AllProperties["ratings_emptyiconurl"] = “_layouts/images/ITIdea.CustomRatings/RatingsEmptyFC.png”;

web.Update();

Uncomment the FeatureDeactivating method and add code:
SPSite site = properties.Feature.Parent as SPSite;�
SPWeb web = site.RootWeb;�
web.AllProperties["ratings_imagestripurl"] = web.AllProperties["ratings_imagestripurl_original"];�
web.AllProperties["ratings_newratingiconurl"] = web.AllProperties["ratings_newratingiconurl_original"];
web.AllProperties["ratings_emptyiconurl"] = web.AllProperties["ratings_emptyiconurl_original"];
web.AllProperties.Remove(“ratings_imagestripurl_original”);
web.AllProperties.Remove(“ratings_newratingiconurl_original”);
web.AllProperties.Remove(“ratings_emptyiconurl_original”);

web.Update();

Deploy and activate the feature and recycle the application pool.
The new custom rating icons are visible and ready to use!
When you deployed the feature, check the Site Options in SharePoint Designer and you will see the original and newly added properties:


After deactivating the feature the original images are set again (and iisreset).