Here is a small tip for developers (about time I wrote one again). What do you do if you want to provision a publishing page to a sharepoint site, and set the page's image (or rollup image) during the provisioning?
Well, step one should be obvious - make sure you upload the image you want to display. This can be done in the same feature or a seperate one. I will assume that you already know how do do that (if not, then the MSDN article "how to provision a file" is your friend). The same goes for actually how to build the feature and module that uploads your publishing page (again, refer to the MSDN article, or better yet, see my friend Waldek's article discussing just this).
So what am I talking about? I want to focus on how to set two specific properties on the page - the page's image and the page's rollup image. These two are not regular properties, since they are publishing properties. They do not expect the same kind of value that regular image properties expect (which is the same as a hyperlink - first part is the link to the image, than a space and a comma and then the description of the image). With publishing fields you need to supply the actual HTML that will be shown as the image.
Since this is done in the module, you will have to create a "Property" element in your "File" element in the module. The value of that property should be the HTML, but encoded so that the XML doesnt become invalid. The value (when not encoded) should look like this:
<img alt='This is a picture of a chicken' src='/PublishingImages/chicken.jpg' style='border:0px solid;'>
And the entire property (with the value encoded) should look like this:
<Property Name="PublishingRollupImage" Value="<img alt='AFL peace Team at Whitten Oval' src='/newsandblog/PublishingImages/22-gal-tn.jpg' style='border:0px solid;'>" />
Hope that helps someone!
Sharepoint Tips And Tricks is Ishai Sagi's sharepoint information blog. It specializes in Microsoft SharePoint technologies, including web parts, development, configuration, customization, and best practices for the use of Microsoft SharePoint Server and Windows SharePoint Services. It also provides some related Office Information, including VSTO and VSTA and other office application development tips.
Friday, October 14, 2011
Setting the images for a publishing page from a module
Sunday, October 26, 2008
Cool new free feature - download all files zipped!
This is a cool one - Mohamed Zaki (fellow MVP) just released an open source feature that allows users to download an entire document library as a zip file.
Take a look at his blog post about it.
Monday, June 30, 2008
Access denied when trying to open a site when on the server
I just wasted half a day trying to figure out why some feature code was not working.
The feature code used HTTPRequest to get a file from the layouts folder- and kept failing with “Access Denied”.
It also turned out that when I logged on to the server I couldnt browse to the site - it asked me for credentials all the time.
After wasting a long time debugging and troubleshooting, this support article saved the day - a little registry change and everything works.
Wednesday, February 27, 2008
New free features by Scott
find new open source features for download on the feature codeplex project.
Includes:
- Applying Unique Constraints to SharePoint List Columns
- Hiding Individual Menu Items on SharePoint Toolbars
- Reset Theme (sets the site theme and logo for every site in a site collection)
Monday, August 20, 2007
Slides from Tech.Ed Australia 2007 - Templates and Features
I start we had the Tech.Ed image:
Next, our names and titles:
Some links and referances:
- http://www.microsoft.com/communities/default.mspx
Solution Deployment with SharePoint 2007 [MSDN]
SharePoint Solution Installer
Scott Hillier’s Open Source SharePoint 2007 Features
How to: Deploy UDFs Using Windows SharePoint Services Solutions [MSDN]
The agenda of the session (Milan covered that):
Here I spoke about the difference between templates (save as template for a list or a site) and definitions (file system xml and aspx files that allow developers and administrators have more control over the sites after deployment)
A quick explanation of how a solution package is built. For example I showed the package of the "print list" feature as it was done by Scott Hillier.
Next I discussed what are DDF files and why we need them (we need them to let makecab.exe know how to build our cab file - using folders), as well as giving some alternatives such as cabarc that allows you to build a cab file with folders in it - no need for a definition file. I also mentioned a tool I never used - WSPBuilder
Now to my part of the demo - I showed how to create a feature for a webpart and how to package it. I used my own Enhanced Content Query WebPart solution package to demonstrate this, and you can download that from codeplex!
After that Milan took over and showed a scenario that used the Solution Generator (part of the WSS extensions for Visual Studio) to create a site definition, with lists that are connected to workflows and have BDC fields and all. It was pretty complex, and I felt we needed more time to really explain it all.
And that was my first presentation. I will let you know about the second one soon.
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
Wednesday, June 06, 2007
My favorite tool just got better!
Check out the post from Karine Bosch.
If you don't know what the CAML Query Builder is, I suggest you start by downloading it (either the new release or the old one) and see how easy it is to write CAML queries with it.
Sunday, April 15, 2007
Changing a list schema in a feature requires IIS reset to take effect
When you build a list definition, and deploy it as a feature, if you make a change to the schema, the change will not take effect until you do IISRESET.
Deactivating the feature and uninstalling it, then installing it and activating it will not do the trick - you must either recycle the application pool or do IISReset.
Tuesday, March 20, 2007
Print list feature improved!
That is why I like open source. Scot Hiller who started an open source project for free sharepoint features took my "Print List" feature and improved it, and published it in codeplex. I wish the referance to me was clearer (it just says "the author" and codeplex doesnt support putting in links in the description! ha!) but I know that Scot did his best with the codeplex interface.
So run to codeplex and download the print list from there. And if you have the time and knowledge - contribute to the project!
Saturday, January 06, 2007
How to add a "print list" option to the list actions menu
It's been a long time since I published a cute and useful code sample, so here we go!
The idea - add a "print list" button to the actions menu of a list, so that when a user click it he will be shown a print-friendly version of the list.
The print list menu item
The print view for an announcement list
Please remember that this is a code sample, and while it works, I can think of many ways to improve it. For example - the current code will always use the default view of the list for the printing, and I would like to improve it so that it shows a print view for the view the user was looking at.
Another example - the current code doesnt display the list title or any other details on the list, and that will be a useful (and easy) modification. I will leave it up to you to try and do it, and if you find yourself in trouble - comment and I will look into what you want to add.
Solution Architecture
The solution will be deployed as a wss feature, which allows us an easy way to add a menu item to the sharepoint menus. The feature will define that the item we want to add will be added to the actions menu of all lists, in a site collection. You can ofcourse change it so that it behaves differently and connects only to lists of a certain type if you so wish, or maybe move the menu item to a different place. I recommend reviewing the msdn article on the possible configurations.
The solution is based on 3 files:
- feature.xml
Defines the feature, its scope and its title that you will see in the "site features" (or site collection features or farm features - depending on the scope)
PrintList.xml
Defines what action we want to add to what menu and what will happen when the user clicks the menu item. This is where you configure the text of the item, and the link to the page that will print the list. which just happens to be the last file:
PrintList.aspx
Contains the code that shows the list in a print-friendly view. This file should be deployed to the layouts folder and must be called with the site's context (more about that shortly).
To the Code!
note - when I talk about the "12 hive" I am referring to the folder C:\Program Files\Common Files\Microsoft Shared\web server extensions\12
Create the page that prints a list:
Log on to the server, and open the template\layouts folder in the 12 hive.- Create a new text file in the folder, and name it "PrintList.aspx"
- Open the empty file in your editor of choice (notepad is fine) and paste the following code into it:
<%@ Page Language="C#" Inherits="System.Web.UI.Page" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<html>
<head>
<title>SharePoint List Print</title>
<link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/core.css" />
<script type="text/javascript" language="javascript" src="/_layouts/1033/init.js"></script>
<script type="text/javascript" language="javascript" src="/_layouts/1033/core.js"
defer></script>
<script type="text/javascript" language="javascript" src="/_layouts/1033/ie55up.js"></script>
<script type="text/javascript" language="javascript" src="/_layouts/1033/search.js"
defer></script>
</head>
<body>
<%
string listId = "";
string referrer = "";
//get the list id (guid in a string format) from the query string
listId = Page.Request.QueryString["list"];
//get the http referrer (for the back button\action)
referrer = Page.Request.ServerVariables["http_referer"];
//make sure the list parameter was passed
if (listId == null)
{
//if a referrer url exists (since the page may have been opened from a direct link, this is not always the case) redirect the user back
if (referrer != null && referrer.Trim().Length != 0)
{
Page.Response.Write("<p>The list ID parameter ('list') is missing from the address.<br>Please go to the list you want to print and try again.</p>");
Page.Response.Write("<p><a href=\"" + referrer + "\" title=\"Go Back\">Click here to go back to the page you came from</p>");
}
else
{
Page.Response.Write("<p>The list ID parameter ('list') is missing from the address.<br>Please go to the list you want to print and try again.</p>");
}
}
else
{
try
{
//load the web object for the site that the page is now in context of
using (SPWeb web = SPControl.GetContextWeb(Context))
{
//load the list that was passed in the 'list' querystring parameter to the page
SPList list = web.Lists[new Guid(listId)];
//load the query of the default view. note - need to modify code in the future to enable multiple view printing
SPQuery query = new SPQuery(list.DefaultView);
//write the list to the page
Page.Response.Write(list.RenderAsHtml(query));
//add the print script
%>
<script type="text/javascript" language="javascript">
window.print();
</script>
<%
}
}
catch (Exception ex)
{
Page.Response.Write("<p>There was an error loading the list information:<br />");
Page.Response.Write(ex.ToString());
Page.Response.Write("</p>");
}
}
%>
</body>
</html>
Install the feature
- Open the \TEMPLATE\FEATURES folder under the 12 hive
- Create a folder called PrintListMenuAction
- In that folder, create 2 text files, one called feature.xml and the second printlist.xml

In your editor of choice (notepad is fine) open the feature.xml file and paste into it the following:<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="769826dd-9dd2-11db-96ca-005056c00008"
Title="Print List"
Description="This feature adds a print command in the Actions menu for Windows SharePoint Services lists."
Version="1.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="PrintList.xml" />
</ElementManifests>
</Feature>
In your editor of choice open the printlist.xml and paste the following:<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Add the action to the List Toolbar Actions Menu Dropdown -->
<CustomAction Id="SPSTIPS.PrintListActionsToolbar"
RegistrationType="List"
GroupId="ActionsMenu"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="Print List">
<UrlAction Url="{SiteUrl}/_layouts/PrintList.aspx?list={ListId}"/>
</CustomAction>
</Elements>
Almost done - install the feature and test it!
To install the feature, open command line (start>run>cmd) and navigate to the bin folder in the 12 hive.
Once there, run the following command to install the feature:
After you ran that command successfuly, you can activate the feature in the site collection either using the user interface (site actions> site settings> site collection features):

or you can (more easily since you are already in the command line) just run the following command, entering the site path:
stsadm -o activatefeature -name PrintListMenuAction -url [your site url here] -force

That's it! if you now go to any list in that site, you should have the print menu action.
Please let me know if any of the steps doesnt work for you or if there is any problem with the pasted code (I am trying the SourceCodeToHTML addin for visual studio, and I am not sure what that will do to simple copy-paste actions on your side).
Update 19/1/2007 :
Some people have remarked that the printlist.aspx isnt working for them. I went over the code and couldnt find a problem with it (well, there are some improvments I can think of, but nothing to cause what they are describing). I suggest you try to troubleshoot it by:
- Make sure you copied all of the text in the code sample. Missing a line or even a character will cause what you are describing
- Try changing the trust level in the web.config file for the sharepoint application to "Full". This shouldnt be a requirement for this solution, but who knows...
- Try removing pieces of code to see what part causes the crash.
- Contact me. Write to my anti-spam email address with the subject "Problem with list printing" (any other subject and I will automatically delete the email). The address is (replace the '$' with '@'):
"dontwantspamhere$gmail.com"
(replace the '$' with '@')
Update 28/09/2007 :
I have noticed that the action only works from within a list view page, and not from a web part (a list view web part) that is displayed on a web part page, not from the list context. I have no idea how to solve it, so for now be aware that this will not work in web parts.