Setting up OpsMgr Knowledge Base on SharePoint 2010 Wiki

Previously, I blogged my opinion on using external knowledge base for OpsMgr. In that article, I mentioned a SharePoint 2013 Wiki solution developed by Stefan Koell. As I mentioned, I successfully set it up in my home lab without issues. However, I had issues setting it up at work, which is still using SharePoint 2010.

After going through what I’ve done with the SharePoint engineer in my company, I was told the issue is with WikiRedirect.aspx. I was told this page doesn’t exist on my SharePoint 2010 Enterprise Wiki site. So to work around the issue, I had to update Stefan’s JavaScript and made it work in SharePoint 2010. The UI looks a bit different than what WikiRedirect.aspx does, but essentially the same. The script redirects to a page if it already exists, or prompt to create a new page if it doesn’t exist.

Here’s what it looks like:

Redirects to an existing page:


Prompt to create a new page:


And here’s the script (I named it RedirectJs.txt):

[sourcecode language=”JavaScript”]
<script type="text/JavaScript" unselectable="on">

// the path to the Enterprise Wiki Site in sharepoint
var SiteUrl = ‘http://Sharepoint/Sites/SCOMKB/’;

// make sure we only execute when a name is provided and when we are not in design/edit mode
var executeMain = false;
if (querystring(‘DisplayMode’) == ‘Design’ || querystring(‘ControlMode’) == ‘Edit’)
executeMain = false;
else if (querystring(‘Name’) == ” || querystring(‘Name’) == null || querystring(‘Name’) == undefined)
executeMain = false;
executeMain = true;

if (executeMain)

function querystring(key) {
// helper function to access query strings
var re=new RegExp(‘(?:\\?|&)’+key+’=(.*?)(?=&|$)’,’gi’);
var r=[], m;
while ((m=re.exec( != null) r.push(m[1]);
return r;

function UrlExists(url)
var http = new XMLHttpRequest();‘HEAD’, url, false);
return http.status!=404;
function load_url(externallink)
window.location = externallink;

function main()
// strip " # % & * : < > ? \ / { } ~ | from name
var name = querystring(‘name’);
name = unescape(name);
name = name.replace("\"", ‘-‘);
name = name.replace(‘#’, ‘-‘);
name = name.replace(‘%’, ‘-‘);
name = name.replace(‘&’, ‘-‘);
name = name.replace(‘*’, ‘-‘);
name = name.replace(‘:’, ‘-‘);
name = name.replace(‘<‘, ‘-‘);
name = name.replace(‘>’, ‘-‘);
name = name.replace(‘?’, ‘-‘);
name = name.replace(‘/’, ‘-‘);
name = name.replace("\\", ‘-‘);
name = name.replace(‘{‘, ‘-‘);
name = name.replace(‘}’, ‘-‘);
name = name.replace(‘~’, ‘-‘);
name = name.replace(‘|’, ‘-‘);
// page url
var pageName = name + ‘.aspx’;
var pageUrl = SiteUrl + ‘/Pages/’ + pageName;
var CreatePageUrl = SiteUrl + ‘/_layouts/CreatePage.aspx?IsDlg=1&Folder=RootFolder&Name=’ + name;
var pageExists = UrlExists(pageUrl);
if (pageExists) {
//open page
} else {
//Create New page

When you use this script, please update the SiteUrl variable to represent the URL of your SharePoint wiki site.


Please note adding scripts to a web part is different in SharePoint 2010 than 2013. The script needs to be uploaded to the site as a separate file then link the the web part. here’s a good article on how to do it.

Note: I have also tested this script on my SharePoint 2013 wiki site. Unfortunately, it does NOT work.


My knowledge on SharePoint and JavaScript is next to none. Therefore, when I was told wikiredirect.aspx was the problem, I had to take his word for it. And I did lots of search online and came up with this JavaScript that worked for me. I won’t get offended if someone criticise me if my statement is wrong about SharePoint and if you think the script can be improved. Smile Lastly, please test it and make sure it works in your environment. I don’t have another SharePoint 2010 site I can test on, the only place I made it work is on my work’s production SharePoint site.

The script can also be downloaded HERE.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: