Thanks!

Content Query Web Part – image on left with formatted date and description

There are tons of blog posts about using the Content Query Web Part to show for example news from an Announcement list. I myself learned a lot from this Heather Solomon post a couple of years ago.

In this post I am going to show you step by step how to create an Item Style for your CQWP that displays an announcements image, title, date and the first 250 characters of the description. This works for Sharepoint Server 2010, and unlike 2007 you don’t have to export the CQWP and change the code – no notepad this time!

 

1. For best practise, I created my own Content Type inheriting from the Announcement Content Type. Lets call this CompanyAnnoucement. To CompanyAnnoucement I added an existing site colum: Rollup Image. Add CompanyAnnoucement to the list(s) you want. If lots of people needs direction on this step, I’ll make a blog post about it.

Continue reading →

Updating Site Title (SPWeb web.Title) programmatically

Scenario:

Sharepoint 2010 (Server or Foundation) is installed, and you also have installed one or more language packs.

You update the SPWeb web.Title programmatically (web.Title = “New Title”, web.Update();) in C#, but the title is not updated in your browser. This will happen if your Sharepoint installation for example is English (1033), and your site is created in Norwegian (1044). It doesn’t matter if the installation language isn’t activated as a possible display language for your site, your updated title will only show when you choose the installation language as Display Language.

If you debug, you will se that the property web.Title is updated, but this is not what is shown in the browser. If you search further through the site’s properties when debugging, you will find a property called m_strTitle that holds your original title and obviously needs to beed updated. But, you cannot update this property directly.

So, how do you update the title in all Display Languages of the site?

SPUserResource resource = web.TitleResource;
foreach (CultureInfo culture in web.SupportedUICultures)
{
Thread.CurrentThread.CurrentUICulture = culture;
resource.Value = "New Site Title";
}

This also applies to for example web.Description, but not web.Name (which also is basis for the Site’s URL).

Remember to call web.Update, and ofcourse to do a web.Dispose if you are not using Using:)

Sharepoint filter with URL values

Did you know that you easily can filter your Sharepoint list or library with values in your URL? This means that you can create a “view” without really creating a view. To spice up your GUI you can for instance insert some graphical boxes above your document library view that filters with URL values. Last, but not least, you can use this method to filter the content of all web parts on a page, you are not limited to filter a view in a document library (after all, a view is just a web part on a .aspx page). You can filter on a built-in column, or a column you have created yourself.

Example:

Continue reading →

Sharepoint naming best practise

When naming your files, folders (but you usually don’t want folders anyway) and sites, avoid these characters:

& ~ # %  * ? / + | ” . _ { } \ : < >

Underscore is to be avoided as the first character in the name, and multiple consecutive periods should be avoided. In columns and document library names I also prefer to avoid Norwegian letters like æ,ø and å, and spaces. I rather rename the column or document library afterwards, getting a nice looking name combined with a coder-friendly URL (I get no sleep when I see URL’s like bad%20url.)

Cascading Drop Down - multiple select

Update: Marc D. Anderson has now updated the Jquery files, so if you use the latest version this won’t be an issue anymore and you can disregard this post.

I have previously written a walk-through about how to implement a relationship between two columns:

http://www.uccorner.com/54/sharepoint/cascading-drop-down/

My friend and excellent SharePoint-er Jasmine Garry found ut that under certain circumstances, this approach did not work. To be more precise, if your site is in another language than English, and your column in the list where the relationship is (i.e. “Vacation Plans”) allows for multiple select, you get this error:

Message: Column not found on page

The reason for this is that the Jquery file uses hard-coded English terms to create a string that works with multiple select.

Solution:

First, in the code for your custom NewForm (the page where you are getting the actual error), look for a select tag and find the one where title=”City possible values”. Possible values will be in your own language. Now open the jquery.SPServices-0.4.8.min.js-file (or the version you are using), replace all occurrences (there are several) of possible values with the equivalent from your own language that you just found in the source code for the page.

Now, do the same procedure for “selected values” and you are good to go.

This is a workaround, and is expected to be fixed in a later release of the Jquery file by Marc D. Anderson.

Thanks to Jasmine Garry and Marc D. Anderson for figuring this out: http://spservices.codeplex.com/Thread/View.aspx?ThreadId=85478

Cascading Drop Down

The request for Cascading Drop Down, filtered drop down, dependent drop down or what you call them is one of the most common requirements from customers. This rather basic functionality is surprisingly not implemented in either WSS 3.0 or MOSS 2007.

Update: This also works in Sharepoint Foundation (2010). I have created a new post for 2010 here.

What is Cascading Drop Down?
You have two columns in your Sharepoint list, Country and City. Both are lookup/drop down columns. When you choose a country in the Country Drop Down, you only want to see the cities in this country available in the City Drop Down column. This of course makes life easier for the end user, and improves data quality.

Solutions en masse
There are however lots of solutions for this. Datacogs’ Cascading Drop Down is well-known, and various improved versions like SharePoint Cascading Drop Down List (With Filter) Field Type and Query Based Lookup Field Control (Custom field controls), both on Codeplex. These are all free, you can also find solutions out there you have to pay for. I have tried several of these, however good work these guys are doing making this for free, there are some issues that keeps me from using them, like annoying page refresh, creating lots of versions of the list element and the general problems you can get with restore/moving/upgrading data that is not standard Sharepoint.

The solution
Instead, I have used this solution with success. The list is still standard Sharepoint, which gives great flexibility and stability. This way, the filtering is done in the forms for creating and editing elements. Because of this, you don’t even have access to the server to implement this. I have used this solution both in document libraries and in regular Sharepoint lists. Continue reading →

Sharepoint: Open links in new window

Ok, this is a simple question really.You have a links list, and want the links to open in a new window. Not really best practise, but a common request for external links. (Best practise is of course to let the user decide – just hold down Shift while clicking the link and it opens in a new window). 

The answer can be simple or a little more advanced, depending on how you solve it:

1.#openinnewwindow

 To add #openinnewwindow to the end of the URL is a common suggestion, but it doesn’t work unless you make some JavaScript modifications.

2. Summary Links Web Part

Using MOSS, you say? Well, let the Summary Links Web Part come to the rescue. This web part is included in MOSS. Add this web part to a page and you can easily customze the links.

Summary Link Web Part

The drawback is that you add and edit the links in the web parts itself, it’s not connected to a list – not the Sharepoint way to do it if you ask me. You’ll have to have Design or Contribute permissions to add links that everyone can see.

3. Convert to XSLT Data View

OK, you only have WSS but you have Sharepoint Designer? Well, just open the page where you have a web part showing links from you links list in Sharepoint Designer.

Right-click – Convert to XSLT Data View.

Convert to data view

Now you can right-click a link and set the target to a new window.

Continue reading →