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 (0) |

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) |

Thursday, May 29, 2008

SharePoint on Windows Vista

"Are you a SharePoint developer tired of starting VirtualPC evey morning when you go to work? Are you dissapointed in remote connection speed and how Visual Studio is slow in there? Then this is the post for you!"

This sounds like a soap opera commercial :) I have Windows Vista installed on my laptop and I am kind of fond of it... Not only because it does it's job :) but also because I have spent a while installing applications and configuring it. So when I work on a SharePoint web part or a Sharepoint MasterPage design, I need to use a remote machine.
Not any more though. The
Bomboo guys found a solution for that. I tried it and so far I installed WSS 3.0 on my Vista, created the first site, installed SPD and created a new masterpage. It all worked.

"Get it today! Available in
stores now!"
Posted by Madalina at 10:17:21 | Permanent Link | Comments (0) |

Monday, March 17, 2008

InfoPath Web Service Main Data Source Change

I recently started working with InfoPath. And, as I did in the beginning, I am still sticking to my first impression about it - it was designed to bring ASP .NET developers down :))

One of the first issues I stumbled upon was the Main Data Source update. I couldn't find this anywhere, and also couldn't make it work. And I desperately needed it, as my form had nothing more and nothing less than 1000 fields :|

Scenario: you have an InfoPath form that submits data to a Web Service. The input parameter of the submit method is an object. If this object has one too many fields and, at a point, changes, or if you move to production server and you need to update the web service URL, then you have yourself a Main Data Source Change scenario.

Wrong Solution: you first try to update the web service url from the Tools -> Data Connections menu option. Here, you can modify the service URL and you do just that. You are then asked to map the web service submit to the datasource on the form. Unfortunately it doesn't work. No matter the options selected here. The object, once in the web service, does not read any of the properties you modified in the InfoPath form.
If you have changed the web service  and now must submit other properties of the object, you notice that the method above does not modify the main data source. It has the old fields still. You can try the Tools -> Convert Main Data Source menu option, but no matter what the input XML file is, the web service still parses an empty object.

Right Solution: I tried all of the above. I struggled for a while and that is why I did not detail the above very much. What you need to know is the solution.
To modify the Web Service Main Submit you must do it the old fashioned way.
Save the form as Source Files. In the directory that you save these files you will find an xsf file, usually called manifest.xsf. In this file InfoPath keeps the web service URL. if you have to update it, do it here.
Also in this folder you will find one or more xsd files. The larger one is the main data source correspondent. In this file you can modify the fields of the main data source. Be careful with the tags. You have to do the same thing in the template.xml file. If you only modify the fields in the xsd file, the field will be shown in Data Source View, but when you try to bind it to a control on the form, InfoPath will return an error saying that the field is not available.

And that is it. After that, open the manifest.xsf in design mode as Save As xsn file.
The web service submit should now work perfectly.
Posted by Madalina at 20:18:11 | Permanent Link | Comments (0) |

Wednesday, March 12, 2008

Munca este intr-adevar amuzanta :)

Din capitolul "Toleranta este un cuvant pe care nu-l cunosc"... Subtitlul "wtf was your teacher?"
 
Am pus mana zile trecute pe un css facut de altcineva. Un css pentru un masterpage de SharePoint. Uitandu-ma prin el sa vad daca pot "fura" vreo idee, am vazut ca unele dintre imaginile folosite in clase aveau calea de forma "../../../../../../imagine.jpg". Ok... Am instalat masterpage-ul (printr feature-ul in care a venit) ca sa inteleg si eu ce imi scapa... Bineinteles ca imaginile nu se incarcau. Am inceput sa ma intreb de unde atatea directoare imbricate.
Singurul raspuns pe care l-am gasit pana acum a fost - le cauta cumva in Google?  =))
 
Posted by Madalina at 14:37:56 | Permanent Link | Comments (0) |

Tuesday, March 04, 2008

iGoogle

Add to Google
Posted by Madalina at 08:34:29 | Permanent Link | Comments (0) |

Tuesday, February 26, 2008

ADO NET Entity Framework Beta 3 Installation Troubleshooting

It is so frustrating to spend a whole day trying to work with a tool and not getting there because you don't know why, but apparently you are installing it all wrong...

ADO .NET EF Beta 3 has 2 patches you need to install in order to be able to use it: Beta 3 patch and EF Tools patch. Or so they say... You also need to install a VS 2008 Patch. I found this tip
here. And installed the VS 2008 patch, then the Beta 3 release and then the Tools. No luck. The ADO NET Entity Data Model Item Template was not showing up in the Add New Item screen of VS 2008. But the VS 2008 command line recognised the edmgen command. Bugger...

After a day and a thousand google searches I found the answer
here. You have to install the VS 2008 patch AFTER the Beta 3 and BEFORE the Tools.

No comment.
Posted by Madalina at 15:48:20 | Permanent Link | Comments (1) |

Friday, February 15, 2008

SharePoint Web Part Rounded Corners - CSS and no inheritance :)

Yes, just as the title reads:
- no custom webparts
- only css styles and images
- any webpart

Lately I have been searching the web for solutions regarding rounded corner webparts. I want to be able to use this solution on any site - so JPEG images as corners are out of question, since I need the webpart displayed on any background. PNG only work in IE7 and above, so first drawback is at the corner.

If you tried working on this much desired skin, you know that the tag layout of the webpart header is not very complex, so you need to play around with CSS selectors and margins and tricks, but none of these combined really does it.

Well here is my trick: the next image is the left corner of the webpart.




If you set this image as background for a TD, the image will stretch as far as the cell goes, so it won't overlap the right corner of the webpart header. You have to make it wide enough for (almost) any resolution/page width/webpart width to display correctly. One the other hand though, many sites today have a fixed width of the main area content, so there you go - you can anticipate how wide the webpart can get.

You also need the right corner image:


Of course, you can use an image that has rounded corners both at the top and the bottom.

And here are the classes:

.ms-WPHeader
{
 background-color:transparent;

}

tr.ms-WPHeader TD /* right corner */
{
 background-color:transparent;
 background-image:url('wpright2.png');
 background-repeat:no-repeat;
 background-position:right top;
 text-align:left;
 vertical-align:top;
 width:35px;
 height:26px;
 margin-top:-1px;
 overflow:visible;
 margin-right:10px;
}

.ms-standardheader.ms-WPTitle /* left corner */
{
 background-color:transparent;
 background-image:url('wpleftlarge.png');
 background-repeat:no-repeat;
 text-align:left;
 padding-left:25px;
 height:25px;
 }

.ms-standardheader.ms-WPTitle A:link, .ms-standardheader.ms-WPTitle A:visited /* title area */
{
 background-color:transparent;
 background-image:none;
 }

.ms-WPHeader DIV /* right corner action arrow */
{
 background-color:transparent;
 background-image:none;
 
 text-align:left;
 width:14px;
 
 overflow:hidden;
 vertical-align:bottom;
 margin-right:10px;
 margin-top:-1px;
 border:0px;
}

.ms-WPHeader TD /* gets rid of the blue bottom border (present in default style)
      under the web part header*/
{
 border: 0px;
}



The IE result:


The Mozilla result:

In Mozilla there is one issue: the webpart actions arrow on the right doesn't recognize the right margin value, so it's right on the edge.


And there you have it. Unfortunately with the drawback of a wide image load, fortunately a solution.

Posted by Madalina at 12:03:04 | Permanent Link | Comments (10) |