Tuesday, June 9, 2009

The Curious Case of Server Side Includes in Sharepoint

At work today I began converting/merging my Centers existing website into a full Sharepoint 2007 solution. For several years now we've had both IIS and WSS 3.0, IIS for the custom ASP development and Sharepoint sites for the teams to collaborate and manage their content.

I hit my first bump today where in customizing the menu structure I found that I can't utilize the <!–– #include virtual/file="file.ascx" ––> option which would be useful for so many things.

Here's the journey I took today in resolving my issue.

After searching the web tirelessly I came across a couple articles that gave me some good not so technical ideas. The one that struck me the most was to utilize DVWP or Data View Web Parts and more specifically the "XML Web Part".

My include file only contained HTML and Javascript this would make it easy to include as the XML Web Part.

How to Build a server side include using the XML Web Part:

  1. In Sharepoint Designer create your include file and save it as a type .xml.
  2. Open <Filename>.xml and wrap the source code in the following;
    <?xml version="1.0" encoding="utf-8"?>
    <HTML><![CDATA[
    YOUR SOURCE CODE HERE
    </HTML>
  3. Save/Close the file.
  4. In your Masterpage (usually default.master) insert the XML Web Part where you want the include content to appear.

  5. In the Web Part Properties set:
    XML Link = <Path>/<Filename>.xml
    Appearance
    Chrome Type = None

  6. Save/Close your master file and you now have an include for basic HTML and Javascript.


I know for advance ASPX/XML developers this is childs play, but speaking from a classic ASP developers point of view this helps our types with oneof the many transition we need to go through. Enjoy, I hope this helps somebody.

2 comments:

  1. can this work in a page layout other than a master page?

    ReplyDelete
    Replies
    1. This should work in any of the server side files. Lately, I wouldn't recommend this as there new web part options that should give the same results.

      Delete