Emil Stoichev's Blog

Just a few coding tips
This blog is moving to a new address


This is the new address. I'll be posting much more about Silverlight so I think that SilverlightShow.net is a better place for my blog. Hope I see you there. Emil

MVP Award
I was presented with the 2009 Microsoft MVP award earlier today! That's pretty exciting for me and I'm glad that my contributions to both online and offline communities were valued so high. I got the award for my contributions in the Silverlight community so I'm a Silverlight MVP. Thanks all for the support! See you Emil
Slides and demos from my presentations at MS Days 09

A bit late but here they are:

Building Mesh-enabled applications using Live Framework

Demo (Mesh-enabled task list - the task list sample from Silverlight.FX framework)


Microsoft Days 2009

This year the exciting conference Microsoft Days 2009 will be held on 14-15 April for IT Specialists and 16-17 April for Developers.

I'll be speaking on 2 topics in the developers track:

Building Mesh-enabled applications using Live Framework

Mesh-enabled applications can be accessed from everywhere – from the browser as well as to be used locally (offline) on the user’s machine. Users can take advantage of the Mesh services such as dedicated sandbox, online and offline synchronization storage, live deployment and update, identity, application catalogues and other. Learn more about the architecture and the lifecycle of the applications living in the Mesh and how to build your own Mesh-enabled Silverlight applications.

Alexandria – business application framework for building Silverlight applications

Alexandria is the code name of a framework for building line-of-business applications with Silverlight and WPF much faster. We will take a look at how to share business logic between the tiers in our applications, how to easy validate data, make CRUD operations, authentication. We will also show the major advantages of the framework such as Page Navigation model that includes browser history integration, deep linking, DataSource and Form controls which give us more productive environment for development of data-driven applications.

I hope see you there!

"Silverlight: Write and Win!" Contest - only 10 days left

Just a reminder for those of you who are interested to share some knowledge with the Silverlight community - you have only 10 days left to submit an article for the "Silverlight: Write and Win" contest running on SilverlightShow.net.

Great prizes - controls suites from the leaders in the field - Telerik, ComponentOne and Divelements + $100 Amazon Gift from SilverlightShow.net

Simple rules - Write an article about Silverlight 2: application, control, game, web services, Blend, design, example, problem solution, effects, animations, library or anything else you find interesting and valuable.

The jury consists of the most deeply involved people in the Silverlight Community - Adam Kinney, Chris Anderson, Dave Campbell, Michael Sync, Shawn Wildermuth, Tim Heuer and I.

Silvester - Silverlight Twitter Widget

Updated to Silverlight 2 RTW!

Since I started using Twitter I've been looking for a cool Silverlight widget I can put on my blog. Well, I found only Flash widgets so I just built a Silverlight one by myself.

Get Microsoft Silverlight

I wrote an article in SilverlightShow.net how it is implemented and provided a full source code for the widget. Read how to put it on your blog and how to build it by yourself.

Unfortunately I'm not able to place it on this blog because of the shrunk CommunityServer features available to me.

Tip: RowFilter with IN operator over a column of type Guid


Apply a RowFilter on a DataView which filters a column of type System.Guid and can contain a variable number of values.


DataView dv = new DataView();
dv.RowFilter = "TypeId in ('<guid>', '<guid>', ...)";

where TypeId column is of a System.Guid type. As the number of values is variable it makes perfect sense to use the in operator.

The problem

When you are looking at this expression you may think this should be working as expected, i.e. the result should only contain the data where TypeId is in the specified values. In fact, if you run it you will get the following exception:

Cannot perform '=' operation on System.Guid and System.String.

The Solution

To convert the String to Guid you should use the Convert(expression, type) method like this:

dv.RowFilter = "TypeId in (Convert('<guid>', 'System.Guid'), Convert('<guid>', 'System.Guid'), ...)";
Tip: Get application based file path with ASP.NET

Linking to a resource from a reusable control in different levels in your web app folder tree can be a tedious and not so obvious task.

We have a number of tools in our bag that we can use:

  • absolute paths - http://www.yoururl.com/a/b/c/page.ext - not acceptable for reusable components
  • relative paths
    • current level based - a/b/c/page.ext - doesn't work for reusable components
    • root based - /a/b/c/page.ext - that works good in some cases but not in every
    • app based - ~/a/b/c/page.ext - perfect when you can use it

What's wrong with root based paths?

When you work on a project you often use built-in WebServer of the Visual Studio and your app runs on http://localhost:XXXX/. Everything seems to be working fine with the root based paths. Now it's time to deploy your app on a test machine. You deploy it on http://test/myBestApp/. Now all your root based paths are pointing to http://test/Page.ext instead of http://test/myBestApp/Page.ext. That's a good reason not to use root based paths.

~ (tilde)

That's a good solution that comes out of the box and takes care finding the root of your app. Ok, but what if need to build the URL on the fly like in this example:

~/Item.ext?id=<% Request.QueryString[ "id" ] %>

This won't work if you put it in a Hyperlink like this:

<asp:HyperLink ID = "hlnkItemDetails" runat = "server" NavigateUrl = '~/Item.ext?id=<% Request.QueryString[ "id" ] %>' />

Don't think about changing the quotation marks. It won't work however you try.

The universal solution - Page.ResolveUrl

Now that's what can help you in every situation (or at least all cases I can think of). Think about this case: you have a custom control in ~/items/controls/ItemViewControl.ascx. This control is used in ~/Default.aspx and ~/items/Default.aspx. You need to link to ~/items/Item.aspx?id=<query string param> from ItemViewControl.ascx. You can't use ~ (tilde), root based, current folder relative or absolute path for some of the reasons written above. This is where Page.ResoulveUrl comes into help. You can build your link in this way:

<a href='<% String.Format( "{0}?id={1}", Page.ResolveUrl( "~/items/Item.aspx" ), Request.QueryString[ "id" ] ) %>' />

Yes, it is a bit complicated, but at least you won't be worried about broken links and they will work as expected wherever you put them.

2008 Launch

8f04d0a7-f17e-4146-9b93-59e0697c1936 I've just registered for the 2008 Launch in Athens. I guess most of you are exciting about MIX08 now but I won't be able to join this event and I'll have to satisfy myself with the 2008 Launch and I hope with the REMIX. I'm sure it will be fun so if you are somewhere near Athens be sure to attend. The event is free of charge. Check out the sessions here.

Tip: How to get the client culture from an ASP.NET app

I fall in a couple of situations where I needed to get the client’s culture from the server side in an ASP.NET application. I googled this and found only client side solutions, but I knew there was some way to get this information because the ASP.NET framework supports client based culture (through the (UI)Culture = "Auto" in the page attributes and the globalization section in the web.config). The only way I thought of getting the client culture was from the Request object.

After examining the HTTP Headers collection I found the Accept-Language header. It contains information about the user's preferred languages. This is a sample Accept-Language header:


The languages are explicitly defined in the browser and their order is determined. You are probably wondering what this q-thing means. According to the RFC 3282 (Content Language Headers) it specifies the language quality or in other words the language priority set in the client's browser. In the example above bg-BG (Bulgarian (Bulgaria) has highest priority then en-US (English (United States)) and the last preferred language is ar-BH (Arabic (Bahrain)).

The Accept-Language header lists all languages set in the browser in a comma separated list which makes it easy to extract each language.

From ASP.NET you can access this header using the Headers collection in the Request object - Request.Headers["Accept-Language"]. Then you can process it the way you like.

Raj Kaimal gave a useful tip that instead of using Request.Headers["Accept-Language"] you can simply use the HttpRequest.UserLanguages to get a sorted string array of client language preferences. Thanks Raj!

I hope you find this tip useful.

Posted: Jan 21 2008, 03:44 PM by Emil Stoychev | with 13 comment(s)
Filed under:
More Posts Next page »