February 14, 2008

Customizing SharePoint Wiki Pages

We were looking at adding additional functionality to the SharePoint Wiki Pages. Our client wanted to classify his Wiki Pages into either of two categories. The home page of the wiki site would lead to a page listing all the wiki pages as hyper links.

The page would look (functionally speaking) something like this.

CATERGORY ONE

CATEGORY TWO

Page 1

Page 2

Page 5

Page 3

Page 6

Page 4

Page 7

Page 9

Page 8

Page 10


Initially they maintained the page by adding the hyper links manually and sorting the pages between the two categories they defined. After using it for a while, they now want this to be an automatic feature. The system should be able to recognize which category a wiki page belongs to and list it under that category on the home page.

Wiki Pages are implemented like SharePoint lists.

  1. Therefore the first thing we did was to add an extra column to the Wiki Pages document library. We added a category look up column and added the two categories mentioned by our client.
  2. Then edited all the exiting wiki pages in the AllItems view to associate the appropriate category.
  3. Then dropped in two list views side by side in a webpart zone and filter them based on the category.

Problem 1: When viewing the Wiki Pages, the category column and its content are displayed below the wiki content which I don't want. The column should appear when editing or creating the wiki page but not when viewing it.

Solution:
Open WKPSTD.ASPX located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\DocumentTemplates\
Look for SharePoint:ListFieldIterator and add the fields you don't want to show up to the ExcludeFields property.

Example:
<SharePoint:ListFieldIterator
ControlMode="Display"
TemplateName="WideFieldListIterator"
ExcludeFields="FileLeafRef;#WikiField;#Field1;#Field2; " runat="server"/>

Problem:
I don't want certain wiki pages to be edited. Like the home page of the site that leads to the list views.
Solution:
Open the page using SharePoint Designer and look for <SharePoint:FormComponent TemplateName="WikiMiniConsole" ControlMode="Display" runat="server"/>.
This has a visible attribute that you can set to false.
<SharePoint:FormComponent TemplateName="WikiMiniConsole" Visible="False" ControlMode="Display" runat="server"/>.

February 8, 2008

How-To: Implement Lock Down on a Site Collection

I really like the STSADM tool. There is so much you can do this. You can implement the lockdown feature on a Site Collection using the STSADM tool.

Why do you want to implement lockdown? Because if you have enabled anonymous users on your site collection, then they can access ALLITEMS.ASPX pages of the lists within your site collection.

Here is the STSADM command:

stsadm

-o activatefeature

-url http://yoursitecollection/

-filename ViewFormPagesLockDown\feature.xml

Note: The MSDN documentation states that this feature is automatically enabled for sites created using the Publishing Portal template.

February 6, 2008

32-bit Emulation Mode on x64 box

The network guys had setup a Windows Server 2003 R2 Standard x64 Edition with SP2 to experiment with and I wanted to check out WSS 3.0 on this. So I downloaded WSS 3.0 x64 and the .NET frameworks and started installing. When I started the setup for WSS, I got an error stating that the IIS was running in 32-bit emulation mode.

I didn't know how to "disable" the 32 bit emulation as it was clear that IIS would not start any 64 bit process. After googling a bit (Ah! What would the modern day Software Engineer do without Google), I found that in order to enable 32 bit emulation you have to change the value of W3SVC/AppPools/Enable32bitAppOnWin64 to 1 or higher and to remove it you need to set the value to 0.

Accordingly, you can go to the command prompt and type:

CScript "%SystemDrive%\InetPub\AdminScripts\adsutil.vbs" set w3svc/AppPools/Enable32bitAppOnWin64 0

Then reset IIS

IISRESET

And the 32 bit emulation should stop working.

February 5, 2008

Saving a Wiki site as site template with Content

Recently, we had a Wiki sub site which was residing on one site collection. We wanted to move it from there to another server under another site collection. I thought the easiest way would be to create a site template with content for the Wiki site and then create a wiki site on the target server using the STP file generated.

I then went into Site Actions à Site Settings à Save Site as Template

The first thing odd about this is that I thought Sub Sites do not have the "Save Site as Template" link in site settings. It is an unsupported feature to type in /_layouts/savetmpl.aspx and create the site template. The next strange thing is when savetmpl.aspx page loaded up it did not have the "Include Content".





I found both to odd. So I went to another sub site in the same site collection, and went to Site Settings. The "Save Site as Template" link as missing here as expected. I then typed in /_layouts/savetmpl.aspx and it loaded the page with the "Include Content" link.

I don't understand this but haven't really had the time to investigate this further.

SharePoint Inspector

SharePoint Inspector is free tool for SharePoint developers that's available from the CodePlex website. As the name indicates, it allows you to inspect various objects within the SharePoint farm in an Explorer like view with properties for each object reflected on the right hand site. It allows you to activate and deactivate SharePoint Features or add event receivers and manage your recycle bin. It's a nice way to have a consolidated look at all your SharePoint objects.

How-To: Backup and Restore

Migrating a site collection from one server to another is a common task for me. Often, the development work is done on our local servers and then moved to a staging server and then to the client's production environment. I have found that the command line utility STSADM is by the far the easiest way for me to move my sites from one server to another. STSADM can be found usually under C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN

For backing up my site collection I use

STSADM     -o backup

        -url http://mysitecollection/

        -filename c:\folder\myfile.dat

After copying the file to the destination server, I then run STSADM to restore the site collection on an existing web application.

STSADM    -o restore

        -url http://mydestinationwebapp/

        -filename c:\folder\myfile.dat

        -overwrite

The overwrite parameter is important to use in scenarios where you have an older backup running or you have simply created the web application along with a site collection. The overwrite parameter instructs STSADM to overwrite the site collection if it exists.

Once this operation has completed successfully you should be able to view you site on the new server. There is however a problem if the target server is on another network (as might usually be the case). When browsing on the new site, it gives you an Access Denied error. You will need to add your local credentials on the new network as the site collection administrator from the Central Administration before you will be able to browse and access the contents of your restored site collection.

Another point to note is that if you have custom webparts that you are using in your application, then these must be individually placed on the target server and you will also need to edit the web configuration file and add the details accordingly.

September 6, 2007

[X] added to webpart having identical titles

Ever had to create a page in a Sharepoint site where the title or the header of webparts are identical. In order to distinguish them, Sharepoint appends [X] to the title. Thus if you add three Content by Query webparts to your page, by default they will be rendered as Content Query Web Part ‭[1]‬, Content Query Web Part ‭[2]‬ and Content Query Web Part ‭[3]‬. Normally you would configure the webpart properties and give them distinct names. Not in this case though since I had to make something of a gateway page to three subs sites. Three images on the page each provide links to the internal sites with the webparts under them. Image on the left would link to the first site and the webpart under it would show a news list on that particular site. Similarly with the other two images and the webparts. I can't provide the screenshot but this is how the page looked.



The requirement was to have all three webpart titles to be "News Update". But adding the webparts to the page predictably resulted in this.



I dont know if there is a better way to solve my problem, but I found that with a little bit of client scripting I could solve it. In a way this solution is similiar to the one I posted on CSS Customization of Webparts. Each webpart title on the page is assigned an internal id by sharepoint which I use to identify the webpart title. Having identified them, I replace the [x] with a blank.

This is how the code would look like.

<script language="JavaScript" type="text/javascript">
//For my first webpart
var content = document.getElementById("WebPartTitleWPQ2").innerHTML;
document.getElementById("WebPartTitleWPQ2").innerHTML = content.replace('[1]','');
//For my second webpart
content = document.getElementById("WebPartTitleWPQ3").innerHTML;
document.getElementById("WebPartTitleWPQ3").innerHTML = content.replace('[2]','');
//For my third webpart
content = document.getElementById("WebPartTitleWPQ4").innerHTML;
document.getElementById("WebPartTitleWPQ4").innerHTML = content.replace('[3]','');
</script>

and my webparts will then look like