Tuesday, June 24, 2008

SharePoint customization - applying a theme programmatically

SharePoint sites can be customized through MasterPages and/or Themes. There are 2 main differences between these two methods:
1. masterpages allow you to rebuild the design from scratch - as in move the elements around on the page as you like - but do not affect system pages
2. themes are made up of css files only, allowing you just to skin a SharePoint site, but are also applied on the system pages.

Customizing a site generally means skinning all its pages. So that the user doesn't get confused as of why some pages look different than others, or at least to give the system pages almost the same look and feel as the rest of the pages.
Automating the masterpage install is easy -you create a feature and write code in the
FeatureActivated event, code that sets your masterpage as the default and custom master(details on that feature are to come in a future post).
But what about applying a theme? The general procedure would be to have the administrator go on the server and copy some files on the Windows drive and then modify an XML file so that SharePoint can read the theme and display it on the Site Settings > Site Theme page. One of the many posts that explains this method is
this one.

But what if you want to do this programmatically? With a feature, like you would do when you deploy a masterpage.

Well, simple enough, this is possible. As long as the theme exists in the THEMES directory, SharePoint can retrieve it. The only reason you modify the spthemes.xml is for SharePoint to display the theme in the Themes list. So if you place the theme in the Themes directory (just by copying it there in a bat file for example) you can use code to apply it:

web.ApplyTheme("MyTHEME");

Since we are here, the way to revert a SharePoint site to the default theme isn't web.ApplyTheme("Default"
), but web.ApplyTheme("none"
).

And there you go - you can programmatically apply a theme to a site. And the way to make the theme "visible" to the user is to have it as a feature instead of having it in the Themes list.

Posted by Madalina at 15:56:17 | Permanent Link | Comments (0) |

Tuesday, June 17, 2008

Programatically add (and remove) an HttpModule to SharePoint Web.config

Sometimes you need to use an HttpHandler or HttpModule in a SharePoint application - I am using one to handle the requests to the system pages and to replace the application.master on them with my own master. To install this module I need to register the dll in the GAC and to add a HttpModule declaration in the web.config.

To modify the web.config programatically in SharePoint you can use the SPWebConfigModification class. There are many examples on the net about using this class, and the one I started with is
this one. Unfortunately, this example, along with all the others on the subject are healing with adding HttpHandler elements, while I needed to play with an HttpModule element. The example does apply to me for adding an element, but the issue arises when I need to remove it.

The SPWebConfigModification class has a Name property. This property should be set to the relative XPath to the modification and maps to the Path attribute of an HttpHandler element. The property is used to locate the element when you need to remove it. Unfortunately, the HttpModule element does not have the Path attribute. So no matter how I tried it, I could not remove the element from the web.config.

The solution came while I was reading a different post about web.config inheritance: the tag. If you want to remove the HttpModule element, add a tag to the web.config.

Posted by Madalina at 11:34:33 | Permanent Link | Comments (2) |

Thursday, June 05, 2008

Don't think outside the box, BE outside the box

I was browsing emag today, and as usual, I went to see what is new in the laptop department. And I found the new Dell 1525, as colorful as ever. I have a Dell myself, an Inspiron 1520 in pink, but this new model is a step further :)


And I started thinking: why does everybody own a gray or black (or dark blue maybe) laptop? Do they want to "fit in"? Fit in where? Underground? Don't get me wrong, I'm not Flower Power :) but I really do ask myself the never ending "why??!?!?" when it comes to this. I heard the "classy" card in relation to the "black laptop" trend. Is it really classier? Do you receive more respect when you, say, go on a conference stage and present ASP .NET (sorry, my thing) in front of an audience from a black laptop? Or are you just another one of many, just a shadow in the crowd?...

Nowadays there are many smart people around, talented people, successful people. The days when you asked "how many of you developed a workflow" in a gathering and one or two people at most raised their hands are gone. Today information is something that everybody has. Everybody has a rocket model at home. So why fit in? Shouldn't we stand out?
You will say that standing out should be related to what you say not how you look. Yeah, right. iPhone is aaaaaaall about the software, that's why you would replace your PDA with it in a minute. Last conference you went to - which presenter do you remember? The smart one? Or the smart one that said it all in the right tone and moved like he was delivering the information with his body language and you don't even know what background color the PowerPoint slides were on? It's all about presentation, my friends.

So don't you dare start rolling your eyes when someone comes into the room and takes out of his/her bag a green tattooed laptop - as he/she is the bold one in the room. You are only blending in. With your gray laptop. Aren't they all...

Posted by Madalina at 18:08:41 | Permanent Link | Comments (0) |

Sunday, June 01, 2008

How development finally pays off

I am a web developer. Not a life-saving job. At all.
Being a software developer is an abstract job. When you go home in the evening, you can't bring anything useful with you. Knowing what Response.Redirect() means, does not help you climb up a tree to save the cat. Learning about stacks in school does not make it less painfull when, at the grocery store, someone ignores the line and skips the waiting part to go ahead. On the contrary.

But today I finally found a use for my being a web dev :D  I was looking at
monster.com. You know, the job search engine. It is divided into countries. If you want to look for a job in sunny Mexico, you have a site for Mexico. And so on. I found it nice at the beginning. But frustrating at a point. Being a freelance consultant, I don't really care where the job comes from as long as it is the job I am looking for. So after going on many of the sites, I started to ask myself why is it that you don't have a Monster site where you can search for the job you want in all the listings of all the countries?

If you are a web dev, you do :D Browse to any site, put in the key word(s) of your search and hit enter. Let's suppose you are searching for "asp net". Results from the current country will be displayed as well as the page URL:
http://jobsearch.monster.com/Search.aspx?re=130&cy=us&brd=1&JSNONREG=1&q=asp+net&rad=20&rad_units=miles
In there you can find the id of the current country and information about the city you could select(zip code, distance from the city etc). All you really need here is the keywords you entered. So if you leave the URL at http://jobsearch.monster.com/Search.aspx?q=asp+net and hit enter, guess what you will get - asp net listings from all the countries.

So yes, 5 years of university, 3 of work... it does pay of to be a web developer in the real world too =))
Posted by Madalina at 19:06:38 | Permanent Link | Comments (0) |