Thursday, June 11, 2009

The Case of Server Side Includes in Sharepoint Continued

So here's the deal in my first article, "The Curious Case of Server Side Includes in Sharepoint", I described how to use XML Web Parts to include HTML pages into Sharepoint. These pages only contained HTML Tags and Javascript, soon after that I had to figure out a way to include Server Side Scripts ie. classic ASP or PHP.

Sharepoint is built on .NET and all you hear is how superior it is to classic scripting techniques but personally its been very hard to retrain my brain not to follow my scripting talents. So here's a crutch for you other script junkies out there that need to add there existing work into Sharepoint today.

So for this you'll need a Sharepoint site, and IIS or Apache server (to host your scripts). I've done some testing and if you own your Sharepoint Server then you can install other Sites under IIS that are ASP supported sites. If you don't own the Sharepoint server then this will also work for Web Servers on another machine.

  1. Write your script as you need it to run (test/debug).
  2. Build your tables, divs, spans or whatever format stuctures as if they were linked to the CSS that the Sharepoint page is linked to (this will maintain the look and feel).
  3. Once you've tested the script wrap the following XML tags around it:
    <?xml version="1.0" encoding="utf-8"?>
    <HTML><![CDATA[
    YOUR SOURCE CODE HERE
    </HTML>

  4. Insert the XML Web Part where you want the script content to appear.

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

  6. Save/Close your file and you now have a Server Side Script include.

I know I'm supposed to be promoting growth into the newer technology but I'm an old dog and sometimes you just need to get stuff done, minus the learning curve. His a bone for the dogs to get by one more day until the light switch of .NET comes on.

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.