1

So we are creating a branded web site for a client to deploy internally (kind of an intranet), but 99% of users won't see the ribbon, just a branded information site.

They want to use the Discussion Board. They want it to look quite different from the standard Discussion Board. We want to have this deployed as a wsp that is the output of our VS2010 project.

We've successfully modified the Main, Thread amd VWStyles xslt files, and can manually deploy them to a subdirectory of the Style Library and edit the view in SPD to set the XslLink and it kinda works (although the style dissappears randomly).

Anyway, we're not sure

  1. how or where to deploy the XSLT files
  2. what the path for the href attribute of the import tag in the main and thread xsl files should be

I'd also like to make a new web part in which these XSLTs were used by default, so I thought of adding "forum" web part to our solution, based on the Discussion Board, but how to I specify these new XSLT file as the default?

1
  • please can you fill me some link or anything that can help me? i have the same need as you and i don't know how to approach it... thnx Commented Sep 24, 2014 at 8:35

2 Answers 2

8

Actually you don't need to modify the OOTB files. In fact, it's a very bad idea, since Microsoft doesn't support modifying any of OOTB files in Layouts directory, except of DocIcon.xml.

Any cumulative update or SharePoint service pack can replace these files, so your customizations will vanish in one moment.

What you need to do, is to create your own file, deploy it to Layouts/Xsl or it's subfolder using SharePoint Mapped Folder approach:

add layouts folder

xslt file

Then, you should provide a link to it using XslLink property. It can be done programmatically.

And to achieve the GUI-enabled reusability, I would modify or create SPView instead of instantiating a detached webpart. That way, any user could deploy a list instance to a particular page and then set your customized view through the webpart settings.

The foundation behind that approach, is that SPView and XsltListViewWebPart in SharePoint 2010 are both representation of the same internal piece of data. And curiously, they share some properties, including Xsl, XslLink and ParameterBindings, so you can control XsltListViewWebPart through the corresponding list view object.

You can easily modify properties of SPView through the code, placing it in a feature event receiver.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    var web = properties.Feature.Parent as SPWeb;
    var list = web.GetList("/Lists/Test");
    var view = list.DefaultView;
    view.XslLink = "myfile.xslt";
    view.Update();
}

And the last note, about the xslt file contents. Of course, you don't need to copy-past all the contents of OOTB files. Just reference them, using <xsl:import href="/_layouts/xsl/{filename}.xsl">, and redefine particular templates.

For your convenience, here is an example of an xslt file:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:ddw1="http://schemas.microsoft.com/sharepoint/soap/"
  xmlns:p1="deskwork" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:system="clr-namespace:System;assembly=mscorlib"  xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
  xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:SharePoint="Microsoft.SharePoint.WebControls"
  xmlns:ddwrt2="urn:frontpage:internal">

  <xsl:import href="/_layouts/xsl/thread.xsl"/>

  <!-- redefine templates here -->

5
  • Thanks for the insights. I may not be an advanced enough Sharepoint developer to understand all that you've suggested. I have a couple of follow up questions - how can I tell if the xslt files have been deployed (where do they show up)? Where do I put the the FeatureActivated method and do I have to know ahead of time where the Discussion Board will be created? Or can I take some action if it's a Discussion Board?
    – Handleman
    Commented Sep 19, 2011 at 23:12
  • Omlin, I managed to get the xslt files deployed. I actually deployed them to xsl/custom so they wouldn't overwrite the standard ones. I added an event receiver and set properties.List.DefaultView.XslLink = "Custom/thread.xsl"; when properties.TemplateId == 108. But it still seems to be using the normal xslt. Any ideas?
    – Handleman
    Commented Sep 20, 2011 at 6:02
  • First of all: How to check if the file was really deployed: you can open your browser and navigate to http://yourportal/_layouts/xsl/custom/thread.xsl and see what happens, or try to find it using windows explorer, under 14 hive: \template\layouts\xsl\custom\thread.xsl. Commented Sep 20, 2011 at 7:14
  • Secondly, FeatureActivated is an overriden method of feature receiver class, so you should create a feature with Visual Studio, and place the code there. Commented Sep 20, 2011 at 7:16
  • The last thing, and the most important: solution I've provided is intended to be used for existing Discussion Board list with particular Url. So as you see, we are fetching list using this piece of code: web.GetList("/Lists/Test");. If you need to share customizations between many lists, you should create a list template, and in your CAML list definition provide XslLink to the default view. And then, you will be able create your lists based on this list template, and they will use the customized Xslt file. Commented Sep 20, 2011 at 7:21
0

I would deploy to the Style Library/XSL Style Sheets// instead of the _layouts folder. That gives you the ability to deploy as sandbox solution too.

2
  • 1
    SPView.XslLink cannot be pointed to outside of 14 hive folder (you can try it yourself if you disbelieve), so the only option in sandbox is to deploy XsltListViewWebPart, which is not reusable. Moreover, you can do this only through CAML, since Microsoft.SharePoint.WebParts namespace is disabled for programmatic access. Commented Sep 19, 2011 at 12:46
  • I was able to deploy to the style sheets folder and once I'd put the board on a page I could set the Xsl Link as one of the web part properties. The problem is that once you click on a discussion topic to see the replies, it uses another view which you can't set the Xsl Link for.
    – Handleman
    Commented Sep 20, 2011 at 23:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.