Monday, February 22, 2010

Add “Edit Item” link or remove “View Properties” link on SharePoint Discussion board Flat/Threaded views

One of my clients had a requirement to add "Edit Item" link on SharePoint Discussion Board Flat/Threaded View like this…

I had searched a lot on the Google to find an answer, but wasn't able to find one. Finally I had decided to dig through SharePoint file system and find how it works.

As we all know all the lists in SharePoint are features so I went in to this location "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\DiscussionsList\Discuss" to open the schema.xml file for Discussion boards. I went through all the code but was not able to exactly find where this "View Properties" link is getting generated. After spending lot of time swimming through the code finally I got a code block which generates "View Properties" link. The code which generates "View Properties" is the field with the name "StatusBar" as shown below.


Now in the "StatusBar" you have something called "DisplayPattern" which contains the code for displaying "View Properties". So I have decided to add "Edit Item" link before "View Properties" link.

Below is the code to add "Edit Item" link before "
View Properties"

I you want to remove "View Properties" link then simply comment the code highlighted in blue.

Note: Making Changes to the Schema file of Discussion Board will affect all the lists of type Discussion Board across the SharePoint farm. So I suggest to create a Custom Discussion Board list definition and implement in that.

You can also add "Edit Item" link like below, without modifying the SharePoint Custom Discussion Board list definition using jQuery Like this…

<script type="text/javascript" src="../../Shared Documents/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//debugger;
//To display edit link after reply
$("a:contains('Reply')").each(function(index) {
//debugger;
var dispFormID = $(this).closest('td').siblings().find("a:contains('View Properties')")[0].search;
dispFormID = dispFormID.substring(0,(dispFormID.indexOf('&', 0)+1));
var itemID = dispFormID.substring((dispFormID.indexOf('=', 0)+1),(dispFormID.length)-1);
var parentID = "&amp;DiscussionParentID="+itemID;
var editformWithID = "EditForm.aspx"+dispFormID;
var editLink = $(this).closest('td')[0].outerHTML;
editLink = replaceAll(editLink,"reply.gif", "edititem.gif");
editLink = replaceAll(editLink,"Reply", "Edit");
editLink = ReplaceAll(editLink,"&amp;ContentTypeId=0x0107", "");
editLink = ReplaceAll(editLink,"NewForm.aspx?", editformWithID);
editLink = ReplaceAll(editLink,parentID, "");
editLink = "<td class=ms-separator><img src='/_layouts/images/blank.gif' alt=''></td>"+editLink;
$(this).closest('td').parent().append($(editLink));
});
});

function replaceAll(txt, replace, with_this)
{
return txt.replace(new RegExp(replace, 'g'),with_this);
}

function ReplaceAll(Source,stringToFind,stringToReplace)
{
var temp = Source;
var index = temp.indexOf(stringToFind);
while(index != -1){
temp = temp.replace(stringToFind,stringToReplace);
index = temp.indexOf(stringToFind);
}
return temp;
}
</script>

Saturday, February 13, 2010

How to Install SharePoint/MOSS 2007 Development Environment on Windows 7

I was surprised to see a hack from Bamboo Nation on installing MOSS 2007 development environment on Windows 7/Vista. Microsoft officially doesn't support SharePoint installation on Windows 7/Vista. Thanks to Bamboo Nation for finding the hack. It makes lot easier for users to practice on their laptops with medium configurations without the need to have high end configurations. Of course with the new release of SharePoint 2010 Microsoft had opened up SharePoint 2010 installation on Windows 7/Vista. Yet to see how easy that is going to be.

I don't want to detail the procedure of installation, which is found here

http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2009/05/07/installing-wss-3-0-moss-sp2-on-windows-7-rc.aspx

http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2008/05/21/how-to-install-windows-sharepoint-services-3-0-sp1-on-vista-x64-x86.aspx

But want to write about a problem that I came across during the installation.

Once you download and install the Bamboo Nation Installation helper you will have to run SetupLauncher.exe. Setup launcher takes SharePoint.exe or OfficeServer.exe as input and extracts the files in to the following directory C:\Users\Your Login\AppData\temp\Xtracted and launches the SharePoint Installation. Problem is here, what if we have a CD and want to use the files from the CD and not download any trial version from Microsoft's site?

Here is the trick, Copy the files from the CD on to this location C:\Users\Your Login\AppData\temp\Xtracted and then point SetupLauncher.exe to the setup.exe file on the CD. It will give a help popup and fail to extract, but launch the SharePoint setup installation. This is how SetupLauncher.exe works.

Note: If you dont see "Create or extend web application" under application management in central admin run your IE as administrator then you will see it.