The WebUtil Class in Sitecore

by aboo bolaky 30. November 2008 06:36

For those Sitecore lovers..

When you code against Sitecore, whether against renderings or sublayouts, I'd suggest you have a look at the very useful methods defined in Sitecore.Web.WebUtil Class. Those methods will help save you some time and prevent you from re-inventing the wheel. Some methods worth mentioning are :-

string AddQueryString(string url, params string[] parameters)
string AddQueryString(string url, bool xhtml, params string[] parameters)
string ExecuteWebPage(string url)
string ExtractFilePath(string url)
string ExtractUrlParm(string name, string url)
Placeholder FindPlaceholder(string key, Control root)
HtmlAnchor GetAnchor(Item itm, string linkField)
Control GetErrorControl(string error, string details)
Control GetFormControl(Page page)
string GetFormValue(string fieldName)
string GetFullUrl(string url, string serverUrl)
string GetHostIPAddress()
string GetHostName()
string GetQueryString()
string GetQueryStringOrCookie(string key, string defaultValue)
void RedirectToErrorPage(string text)
string RemoveQueryString(string url)
void ReloadPage()
string ReplaceUrlParameter(string url, string replace, string withtext, bool append)

Alternatively, you can have a peek at all the methods in the screen grab below [Click on the image for a better view..]

Tags:

.Net | Applications | Sitecore | Tips & Tricks

SEO Friendly Urls in Sitecore -Remove spaces in Url

by aboo bolaky 29. November 2008 09:50

Aliases in Sitecore

Sitecore has the concept of "Aliases", whereby each item can accessed using a specific name (rather than the default path). Aliases are turned on by default. To turn them off, you can flip the web.config settings name AliasesActive to false (But who would want to do that???? Sealed)

Space Characters in Sitecore

When you create an item in Sitecore, you free to choose the naming of your item (provided it succesfully validates against some key rules .e.g Item name cannot contain :,?.. otherwise, you will end up with a "Item xxx is not a valid name"). Most of the time, you will want to put spaces in the item name. Let's take an example:

If an item (at the root level) has an item name of "John Doe", the url of the actual page should theoretically be http://hostname/John%20Doe .

Of course, you can get rid of this spacing issue by specifying an Alias of John-Doe on the item itself. But imaging you having hundreds of items with spaces !!!..

The encodeNameReplacements element in the Web.config

This encodeNameReplacements settings allow you to globally replace any unwanted character in your url to a character of your choice. So, rather than creating an alias for each item (without spaces), we can add the following new setting.

<encodeNameReplacements>
	<replace mode="on" find="&" replaceWith=",-a-,"/> 
	<replace mode="on" find="?" replaceWith=",-q-,"/>
	.....
	<replace mode="on" find=" " replaceWith="-" />
</encodeNameReplacements> 

Job Done ! Cool

 

Tags:

.Net | Applications | Sitecore | Tips & Tricks

SpeedDials for IE7 and Firefox

by Aboo Bolaky 28. November 2008 12:47

Orginally incorporated in Opera, the SpeedDial feature has proved to be an asset for day-to-day web browsing. The whole point of the SpeedDial is to make browsing your TOP N favourite websites as easy as possible.

It didn't take long for the other competitors to follow suit.

Internet Explorer

IE7PRO has created an addon for IE7. Its FREE and packed with loads of features and configuration options (Easy Homepage <==> Speed Dial). It's just too bad that the x64 bit version hasn't yet been released. All in all, this is the ultimate plugin for IE7.

Firefox

The Firefox addon created by Josep del Rio is pretty much geared towards the SpeedDial concept (unlike IE7Pro, which has many other features). The cool thing about this addon is that you can export your settings for your speed dials and import them later on another firefox browser. The current release is Speed Dial 0.7.2.6 and can be accessed at https://addons.mozilla.org/en-US/firefox/addon/4810.

Tags:

.Net | Applications

Method Overloading in WCF

by aboo bolaky 24. November 2008 07:32

In WSDL-based operations, method overloading is hard to achieve. It's not as easy as it would seem with C++ or even C#, where an interface could be defined as

[ServiceContract]
public interface IHelloWorld
{
	[OperationContract]
	void Add(int num1 ,int num2);
	[OperationContract]
	void Add(string s1, string s2);
} 

When you implement this interface in your class, the code (if it's well written Sealed) will compile just fine. The moment you update your service reference, it all goes crazy. The Error Message is "The Request failed with the error message : Cannot have two operations in the same contract with the same name".

The resolution is to add the Name attribute to the OperationContract on each method defined in the interface.

[ServiceContract]
public interface IHelloWorld
{
	[OperationContract(Name="AddNumber") ]
	void Add(int num1 ,int num2);
	[OperationContract(Name="ConcatenateStrings")]
	void Add(string s1, string s2);
} 

When proxy is generated on the client, the operations now have aliased names.  NICE !!

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="HelloWorldRef.IHelloWorld")]
public interface IHelloWorld 
{
	[System.ServiceModel.OperationContractAttribute(
		Action="http://tempuri.org/IHelloWorld/AddNumber", 
		ReplyAction="http://tempuri.org/IHelloWorld/AddNumberResponse")]
	void AddNumber(int num1, int num2);

	[System.ServiceModel.OperationContractAttribute(
		Action="http://tempuri.org/IHelloWorld/ConcatenateStrings",
		ReplyAction="http://tempuri.org/IHelloWorld/ConcatenateStringsResponse")]
	void ConcatenateStrings(string s1, string s2);

} 

Tags:

.Net | WCF | Tips & Tricks

Using Microsoft Search Server Express 2008 Web Services

by Aboo Bolaky 21. November 2008 09:39

WebService Location

The Url for the webservice is usually in the form of http://servername:portnumber/_vti_bin/Search.asmx

PS: Make sure you enter the actual server name instead of the IP address. Otherwise, you might end up with an ArgumentNull Exception when trying to invoke the QueryEx webmethod.

PS: Always call the Status Webmethod (returns "ONLINE" if the search service is up and running) prior to actually querying MSSE 2008.

Crawling Content

To be on the safe side, always add a crawl rule with a path of http://www.targetsitetocrawl.net/*  and a crawl configuration of "Crawl complex URLs (URLs that contain a question mark (?))". Otherwise, the crawler will ignore pages that contain querystrings. Big thanks go to David for pointing this out to me.

Search Scopes

You would use search scopes where you may want to query within "specific parts of a collection". This is analogous to collection/subcollections in Google Mini. The gotcha here is that if you specify a search scope in your query (either SQL-Like query or keyword based query), you might end up with an "Scope in your query does not exist. " error message. This is not the end of the world. The problem here is that you search scope is supposed to be SHARED across the Shared Services Provider. Now, how do we create a shared scope? It's kinda hard to figure this one out. When you normally create a search scope, there is no option to choose whether or not the scope can be shared.

Creating a Shared Scope in MSSE 2008.

The only way I found to create a shared Scope is to create a search scope using the normal approach (Scopes for this search Server ->New Scope). Once you return to the View Scopes page, notice that there is no Create Shared Scope on the drop down list for the target search scope. The current url looks like : http://servername/_layouts/viewscopes.aspx?mode=site. Substitute the mode=site querystring key pair with mode=ssp and hit Enter. You are now in Shared Services Provider mode. When you view the items in the drop down for your search scope, you now have an option to "Make Copy as Shared". Once this is clicked, a Shared Scope with a name of "Copy of .." is created. Of course, do not forget to add rules to your search scope.

You can then manually update your new search scope on the Search Administration Home Page. Once the update is complete, you can use your name of shared scope in your Query XML. One thing i noticed is that there is no place where I can update the name of the Search Scope. weird.. If you know how to do this, please drop me a few lines. i'd be interested to know :P

Word Stemming

This is disabled by default. To enable stemming, you need to perform a basic search on the Search Center Site. On the result page, go to Site Settings -> Edit Page. Edit the webpart Search Core Results (Modify shared webpart). Expand Results Query Options. Make sure the checkbox Enable Search Term Stemming is checked. Voila !!

I hope this is enough to get you going with Microsoft Search Server Express 2008. Cool

 

Tags:

.Net | Applications | Tips & Tricks

What is your deepest fear?

by Aboo Bolaky 21. November 2008 06:34

Our deepest fear is not that we are inadequate.

Our deepest fear is that we are powerful beyond measure.

It is our light, not our dark that most frightens us.

Your playing small does not serve the world.

There is nothing enlightened about shrinking so that other people don't feel insecure around us.

We are all meant to shine as children do.

It's not just in some of us; it's in everyone.

And as we let our own lights shine,

We unconsiously give other people the courage to do the same.

As we are liberated from our own fear, our presence automatically liberates others.

 

Source: Coach Carter

Tags:

The AByss

Paging and Sorting in a Gridview without using an ObjectDataSource

by Aboo Bolaky 20. November 2008 19:43

Ryan Olshan has created a nice article about Paging and Sorting in a Gridview without using an ObjectDataSource. It's pretty nifty and gives you an insight at you can programmatically do with a GridView.

The article can be viewed here.

Tags:

.Net | Asp.Net

Creating a collapsible HTML List using JQuery

by Aboo Bolaky 17. November 2008 17:19

Yesterday, I came across this really nice article by Jeroen Coumans that explains how to create a collapsible HTML list using JQuery. The reasons why I like his solution are:

1. It's simple and easy to understand. It takes only a couple of lines to write the JQuery code.

2. It allows you to add the "active" CSS class to the selected item in the list.

3. Most importantly, it allows you to have a clickable parent item (where the link to the parent item doesn't just point to a #; it can refer to other pages on your site) 

You can have a look at the article here

 

Tags:

.Net | Asp.Net | Tips & Tricks

Creating a nested html list for the Category List in BlogEngineNET - Part Two

by Aboo Bolaky 12. November 2008 10:09

Quick Recap:

Part One : Outlines the steps required to build an nested HTML List for the Categories in BlogEngine.NET. The List can then be used on the FrontEnd section of the site.Full details of the walkthrough can be found here.

I've been working on Part Two of the solution (obviously,this builds upon the work done in Part One), which is about binding the Categories collection to a treeview control, thus making life a lot easier on the backend page. Walkthrough of Part Two

I do reckon that there is a lot to read on those two articles ..but I hope it's well worth it !! Cool

 

Tags: ,

.Net | Applications

Creating a nested html list for the Category List in BlogEngineNET - Part One

by Aboo Bolaky 8. November 2008 12:18

I've been following up the success of BlogEngine.Net closely and amongst its successful releases, I noticed that the Category List control has hardly changed at all.  Am I being too fussy here or is it time for a change?  I must admit that BlogEngine.Net is based on a rock-solid platform and has indeed exceeded my expectations in terms of architecture and extensibility.

[Kudos to the BlogEngine Team]

The purpose of this article is to outline the steps required to produce a nested list of categories from BlogEngine.Net.

UPDATE (08th November 2008):

WHERE is the article? I realised that the article is too lengthy to be included as a post. So i decided to create a Page instead : Creating a nested html list for the Category List in BlogEngineNET

I'm currently working on PART TWO of the article. Well, you ask, what is PART TWO about? In a nutshell, it will allow you to bind the Category List to a treeview control (for use in the admin section). 

Please let me know what you think. Cool

  

UPDATE (12th November 2008):

Part Two has just been published. You can access it here

Tags: ,

.Net | Applications

Tag cloud

Flash Player 9 required.

About Me

I wish I could write something here..
//TODO: ElaborateMe