Monday, May 18, 2009

Override font tag

We had a problem where the content owners were selecting font size from the rich html editor and deploying their content, where as the standard font size across the SharePoint portal was 11px. Problem is when we select font sizes from the html editors it does not allows them to select in pixels, instead they have to select font sizes from 1 through 7. Now the challenge is that we have in map font sizes in to pixels like this.

Font size 1 = 10px
Font size 2 = 11px
Font size 3 = 12px
Font size 4 = 14px
And so on….

I have goggled for some time and got the solution. Here are few links that helped me.
http://www.webmasterworld.com/css/3642874.htm

http://www.ozzu.com/programming-forum/how-override-the-font-tag-with-t74514.html

http://codingforums.com/showthread.php?t=18876

http://www.acquestech.com/2009/01/overriding-inline-css/

http://css-tricks.com/override-inline-styles-with-css/

After looking in to this links I have got two solutions, one which works only for IE
<style type="text/css">
/* For IE*/
font
{
font-size:expression(setFontags(this.currentStyle.fontSize));
}
</style>

<script type="text/javascript">
function setFontags(x)
{
var y={1:9,2:11,3:12,4:14,5:24,6:32,7:48};
return y[x]+'px';
}

</script>

Other which works for IE and Firefox. But the problem with this one is there will be a small flicker to map the font sizes since we had written it in JavaScript.

<script type="text/javascript">
window.onload = function()
{
//debugger;
// Get the (note depreciated) FONT elements
var fonts = document.getElementsByTagName('font');

// Loop through them
for(var i=0; i<fonts.length; i++)
{
// Moz / Opera
// We don't check for removeNamedItem explicitly
// because for some strange reason IE7 acts like the method exists
// but doesn't provide the functionality or return reference to it in a "for prop in" loop.
// Opera supports both methods of monitoring events,
// Opera also makes the text smaller than it should be if we use the same method IE uses
// so we check for the Moz method of monitoring events
// which is known not to work in IE
if( fonts.item(i).addEventListener )
{
//fonts.item(i).attributes.removeNamedItem('size');
if(fonts.item(i).size == 1)
{
fonts.item(i).style.fontSize = "10px";
}
else if(fonts.item(i).size == 2)
{
fonts.item(i).style.fontSize = "11px";
}
else if(fonts.item(i).size == 3)
{
fonts.item(i).style.fontSize = "12px";
}
else if(fonts.item(i).size == 4)
{
fonts.item(i).style.fontSize = "14px";
}
}
// This is how IE7 does it
else
{
if(fonts.item(i).size != "")
{
if(fonts.item(i).size == 1)
{
fonts.item(i).style.fontSize = "10px";
}
else if(fonts.item(i).size == 2)
{
fonts.item(i).style.fontSize = "11px";
}
else if(fonts.item(i).size == 3)
{
fonts.item(i).style.fontSize = "12px";
}
else if(fonts.item(i).size == 4)
{
fonts.item(i).style.fontSize = "14px";
}
}
}
}
}
</script>

Thursday, February 19, 2009

Sort a Data View Web Part based on QueryString

There was a requirement where I have to sort a data view webpart on multiple parameters like date, size and LOB. Initially I thought of having three different pages for sorting, but that is very bad idea. So thought of implementing it with the concept of query string.

I want to use the sort option provided by data view web part and provide SortField as query string parameter. After thinking for a while and providing multiple hit and trials I have succeeded. Below is the expression for sorting using query string.

@*[name()= $SortField]

We write this in the edit sort expression.

And in the URL….

http://ServerName/Lists/Deals/LOB.aspx?LOB=All&SortField=Deal_x0020_Date



Thursday, February 12, 2009

Apply multiple conditions to filter data in Data View web part

I was wondering if there is a way to filter the data present in data view web part by applying multiple conditions like this

If((@ApprovalStatus = 'Approved') and (@LOB = $Param1 or $Param1 = 'All'))

After thinking for sometime, I got an idea to add XSLT filtering instead of applying filter criteria available.



So I have checked the checkbox “Add XSLT filtering”, clicked on edit and added the following XSLT like this:

[(@ApprovalStatus = 'Approved') and (@LOB = $Param1 or $Param1 = 'All')]

Sunday, February 8, 2009

Displays one announcement at a time using DataView webpart

I had a requirement in my project where I had to customize the display of announcements. I was supposed to display single announcement at a time, providing the provision for the user, to navigate through the list of announcements one by one. User should be able to view next, previous and all the announcements. This needs to be done without writing any code.

Here is my approach for this problem. I have created a view for the announcements list which contains required columns along with the Id column. ID column is mandatory for this approach. Using SharePoint designer, in the announcements list I have created a custom form. Use this custom form to display one announcement at a time. Place a data view webpart on this form and customize it to accept query string for ID column to display that announcement.

Place Bank To all View Previous View Next links on the top and bottom of the webpart in this way.



Use the following JavaScript to access and display one announcement at a time.








Monday, November 24, 2008

Process to Remove Delete Permissions On SharePoint List

I got a requirement from my client asking me to remove delete permissions on SharePoint List except for SharePoint site Owners group. Thought for a while for the solution, went ahead and create a new SharePoint permission set without delete permission. That's it, task has became very easy. Now go in to the list settings and select list permissions. In the Actions menu select Manage Permissions. you will be prompted with the message that "You are about to create unique permissions for this List. changes made to parent site will no longer refer to this list.". Select Ok. Now select the appropriate SharePoint groups and remove the existing permissions and add the permissions which you have just created. your task is done.

Thursday, November 13, 2008

Adding BreadCrumb Navigation to SharePoint Application Pages

With the help of following Blogs I was able to get BreadCrumb on to the SharePoint Applications pages.
http://weblogs.asp.net/jan/archive/2008/04/16/adding-breadcrumb-navigation-to-sharepoint-application-pages-the-easy-way.aspx

http://www.novolocus.com/category/sharepoint/branding/breadcrumbs/
And some additional links which can be done through object model code.
http://blog.thekid.me.uk/archive/2007/01/17/configuring-the-breadcrumb-for-pages-in-layouts.aspx

http://www.mikhaildikov.com/2007/05/creating-dynamic-breadcrumbs-in.html

But the requirement from the client was that they want to see default.master with the SharePoint Application Pages and not Application.master. as we all know that all SharePoint Application pages uses application.master and not default.master page. I have googled for some time and found this wonderful Blog from Jan Tielens which helped me to change the master page from application.master to default.master.
http://weblogs.asp.net/soever/archive/2006/11/14/SharePoint-2007_3A00_-using-the-masterpage-from-your-site-in-custom-_5F00_layouts-pages.aspx

This took me in to new problem. The above technique for adding BreadCrumb navigation bar does not work. Then I have played around for some time and figured out the problem. BreadCrumb Navigation bar was not comming since I was changing the master page on the fly through code on page OnPreInit event. Technique mentioned in the above blog posts works for SahrePoint Application Pages only if the master page is application.master and not default.master. So I have learned that application.master uses "SPXmlContentMapProvider" as SiteMapProviser and default.master uses "SPContentMapProvider" as SiteMapPrivider. This helped me to solve the problem. I have just provided "SPXmlContentMapProvider" as SiteMapProviser as source for my default.master in the following way.

SharePoint Application Page Template



Code Behind

using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace YourNameSpace
{
public class ClassName : PageBase
{
///
/// Variables declaration which includes control names in the .aspx page template
///

///
protected override void OnLoad(EventArgs e)
{
}
}
}