Sunday, May 6, 2007

Adding the quick launch to team site pages

Hi All


Ever tried to add a new page in a WSS Team Site?

Well, after you create a new page, using the "Create web part page" wizard:





you probably noticed the following issues:

1. You have to create a document library to store them (unless you save them in "Shared Documents" library, but we wouldn't want to mix documents and site pages, would we?)

2. They look different from the team site's home page - where did the quick launch go??







OK, so the solution is quite simple, and there are 2 cases here:


1. If you have MOSS 2007 - All you have to do is to activate the "Office SharePoint Server Publishing" feature for your team site. Once you activate this feature, the team site will have some publising site features: a new "pages" library will be created, and all new created pages will be automatically stored in this library. In addition all pages will display the same "envelope" - including the missing quick launch on the left side of each page.

The only problem with this solution is that now every change you make requires publishing, and this is certainly NOT a natural part of team-site working flow.


2. If you only have WSS installed - in this case you don't have the "Office SharePoint Server Publishing" feature installed. however, you can change the team site page templates, and have them display the quick launch. This is quite easy to implement, so here it goes:
  • Browse the "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\STS\DOCTEMP\SMARTPGS" folder on the SharePoint server.
    This folder contains all templates that you see in the "New Web Part Page" wizard:



  • Every page inherits the same team site's master page, and all of them override this master page's placeholder tags. This is why the quick launch is not displayed in new pages created in a team site (don't ask me why it was done like this, I don't have a clue..).


  • Simply delete the "PlaceHolderLeftNavBar" content tag in the required templates and save the file/s:


That's it!


Now, create a new web part page, based on the template you have just changed, and notice that the quick launch appears exactly as it is in the home page.

One last thing to remember:

Since the changes are done in the file system, these changes apply to all team sites on your SharePoint server.



Nimrod Geva
KWizCom - Knowledge Worker Components











Friday, May 4, 2007

UTF-8 with signature?

Few days ago I was at my customer and we witnessed a wired behavior of excel.

We wanted to display data in excel from the web, so that when you click a link excel will open and display some data in it (not within explorer).

Doing this is pretty simple, all we have to do is create a data grid control, bind it to a data source and let it render.

When we want it to open to excel we have to replace the "pre-render" method with this simple code:
Page.Response.Clear();//clear other HTML form response
Page.Response.AddHeader("Content-Disposition", "attachment;filename=StudentsList.xls");//to open in excel
Page.Response.Charset = "65001";//for UTF-8
myDG.RenderControl(writer);//render grid HTML
Page.Response.End();//End response here.

This works great for most cases.

My client had to display some non-English characters that were all UTF8 encoded. When saving the result HMTL in notepad using UTF8 excel was able to display the special chars ok, but when using the code sample above - we got some wrong data.

After googling around for a while i managed to understand that excel must use UTF8 with signature text and i had to add a signature to it.

So - how do I signature my file as UTF8???

Some more googling allowed me to learn that all I needed to do is add these bytes to the start of the file:
0xEF, 0xBB, 0xBF

Using C#, here is the complete and correct way to do this:

Page.Response.Clear();
Page.Response.ContentType = "application/vnd.ms-excel";
Page.Response.AddHeader("Content-Disposition", "attachment;filename=StudentsList.xls");
Page.Response.Charset = "65001";
byte[] b = new byte[] { 0xEF, 0xBB, 0xBF };
Page.Response.BinaryWrite(b);
myDG.RenderControl(writer);
Page.Response.End();

Now everything should be rendered okay and my file is saved with UTF8 with signature!!!

Hooray!

Well, hope this helps, since I didn't manage to find any document that explains this I thought it might help if I publish one...

Peace, Shai.

Tuesday, May 1, 2007

Un Documented Navigation Control using C#

Hey All,

I run into a requierment during a site creation automation at one of my customers.
In this automation we had to dynamically add links to the site's navigation only to learn that the sharepoint API for this is not what I expected.

What i needed is to do some simple things (or so i tohught) like adding header items, adding items with no link, specify links to open in new window etc...

well i came across some undocumented things that helped me do these not so simple tasks... I added here some of the code I used so it may help so of you out there.

I wanted to add navigation controls like:
· No link (href) for new navigation item (not as simple as you thing… I wanted it not to behave as a link.)
· Add a link that will open in new window
· Create a container navigation item to hold several child links
All of these are fairly simple to do using the UI, but not so simple when using code to create the links.
I did manage to control each of these features using navNode.Properties
Now, I could not find any documentation regarding how we suppose to do it, so what I had to learn myself is not documented so far anywhere I looked.

Now, with no further ado, here are some source code samples I collected:
Use this to add a container with no link:
navNode = new SPNavigationNode("Container", null, true);
navNode = CourseWeb.Navigation.QuickLaunch.AddAsLast(navNode);
navNode.Properties["UrlFragment"] = "";
navNode.Properties["NodeType"] = "Heading";
navNode.Properties["BlankUrl"] = "True";

Use this to add a link in the container:
SPNavigationNode tmpNavNode1 = new SPNavigationNode(LinkName, LinkUrl, true);
tmpNavNode1 = navNode.Children.AddAsFirst(tmpNavNode1);
tmpNavNode1.Properties["Target"] = "_blank";
SPNavigationNode tmpNavNode2 = new SPNavigationNode("Second link", "link url", true);
tmpNavNode2 = navNode.Children.AddAsLast(tmpNavNode2);
tmpNavNode2.Properties["Target"] = "_blank";//open in new window

navNode.Update();
tmpNavNode1.Update();
tmpNavNode2.Update();
CourseWeb.Update();

Well, I know I spent a lot of time to find how and what to do… could it be that SharePoint team cut few corners in the API?

Anyway, hope this helps some of you developer guys,
Shai Ben Shooshan