I came across an interesting problem while developing a "Team Space" SharePoint site. When you add the option for users to create "New Folders" in lists or Libraries, there is not a slick way for the users (once inside the folder) to navigate out, other than use the back button.
There is probably a very simple solution for this; however, with all the research I did, I haven’t been able to find anything that will work for my requirements.Phase 1 solution - My first requirement was to add a back button to document library and picture library. This proved more difficult than it should be (and I'm sure there is an easier way). What I did was write a file called DocumentBackButton.ascx put in the 12/TEMPLATE/CONTROL TEMPLATES folder. This file overwrites the defaultTemplates.ascx Sharepoint:RenderingTemplate because I gave it the same ID as the one in the defaultTemplates file. All this file basically does is calls a new toolbar.ascx file I created called DocumentToolBar.ascx. Inside the DocumentToolBar.ascx file, I put the following javascript code inside to create a back button: <HeaderHtml> <script type="text/javascript"> urlquery=location.href.split("?"); if (urlquery != "") { checkRootSplit=urlquery[1].split("="); checkRoot=checkRootSplit[0]; } if(checkRoot == "RootFolder") { window.onload = show_div; } function show_div() {document.getElementById("upImage").style.visibility="visible"; document.getElementById("upImage").style.display="block"; document.getElementById("upSeperator").style.visibility="visible" document.getElementById("upSeperator").style.display="block"; } </script> <td class="ms-toolbar" nowrap="true"><div id="upImage" style="visibility: hidden; display: none"> <a href="BLOCKED SCRIPThistory.back()"><img tabindex="-1" id="tbbutton_UpToParentButton_img" src="/_layouts/images/upfolder.gif" alt="Up" border="0" width="16" height="16" /></a> </div></td><td class=ms-separator> <div id="upSeperator" style="visibility: hidden; display: none"> <img src='/_layouts/images/blank.gif' alt=''> </div></td ></HeaderHtml>
This solution worked fine for a time. The problems with it are; the JavaScript is just hiding the div, the code is on every page that uses this .ascx file, there is a delay from the page load to the back button showing up, and this is a lot of code. This solution also only provided the history.back functionality, not a ‘true’ up one level. And it doesn’t work with the list libraries, because they don’t use the same DocumentBackButton.ascx. (I haven’t been able to find the link to the .ascx files in the list areas).
Phase 2 solution – Now that I had to put the back button on tasks and contacts (list items), I had to come up with a different solution. This time, I spend a lot of my time trying to find the ty into how the rendered page was using the .ascx Control Templates. I wasn’t successful. So I finally figured out which file was being used, ToolBar.asxc. I went right into this file and modified it directly with the following code:
<% if (Page.Request.QueryString.Count > 1) { if (Page.Request.QueryString["RootFolder"] != "") { String myPath = Page.Request.FilePath.Replace("/" + System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"]), ""); if (!myPath.Equals(Page.Request.QueryString["RootFolder"].ToString())) { String myURL = Page.Request.RawUrl.ToString(); myURL = myURL.Replace("%2f", "/"); String partToModify = Page.Request.QueryString[0]; String MainString = "String Manipulation"; String[] Split = partToModify.Split(new Char[] { '/' }); String afterModified = partToModify.Replace("/" + Convert.ToString(Split[Split.Length - 1]), ""); String endURL = myURL.Replace(partToModify, afterModified); Response.Write("<td class='ms-toolbar' nowrap='true'>"); Response.Write(" <a href='" + endURL + "'><img tabindex='-1' id='tbbutton_UpToParentButton_img' src='/_layouts/images/upfolder.gif' alt='Up' border='0' width='16' height='16' /></a> "); Response.Write("</td><td class=ms-separator><img src='/_layouts/images/blank.gif' alt=''></td>"); } } } %> This code is only going to run if there is a ROOTFOLDER as a parameter in the URL. Because there is a pattern in the URL, I could figure out where in the structure I was. I can figure out whether to go up one level, or if there is a level to go up.
I’m sure there is an even better way to do this. Please let me know if you know another way to accomplish this functionality. Also, I haven’t provided very detailed instructions or comments, I would gladly do so if there was interest.