WebLog

Server-side, client-side, code snippets, scripts, automation, best practices, proven approaches, tips & tricks...

Maintaining same session with separate web requests from C# code

Create separate web requests with the same server session
0
Recently I started a small project for image optimization which relies on public image optimization services available online. For now it supports Yahoo SmushIt and Compressor.io services, but it will be extended over the time. Project is open-source and hosted at GitHub https://github.com/dejanstojanovic/ImageOptimization. ...read more

Getting social network access token from C# backend

Acquire Facebook or Google+ access token from C# code
0
Most popular social networks such is Facebook and Google+ are providing authentication for web applications with fancy javascript pop-ups. However this approach might not work in all browsers and most likely not on every device. For example this approach does not work on iPhone or iPad because browser itself does not allow pop-ups...read more

Access auto property backing field with reflection

Access property fields of auto property in C#
0
Using reflection you can easily access any property, filed, methods, pretty much anything of any type in .NET. Reflection is never the most elegant way to do something, but sometime you just have to do it. In older versions of C#, to declare a simple property in a class you would have to declare a private field which will be exposed by the property outside the class ...read more

Same page language switching in Umbraco

Land on the same page in different language in Umbraco using Relations
0
When we build multi-language website, we usually create two root elements which represent different language websites. To switch the language you just need to add a link to other root elements which represent other languages of the website. With this approach, when you switch language you will end up at homepage of the language regardless which page you were viewing. ...read more

Filesize to proper display string

Display size of file in the proper maner
0
How many times you had to display file size on your web page? Pretty much every time you might have the same issue with recalculating size to KB or MB. I caught myself doing this for so many times over and over, so finally I decided to write a piece of code for that. ...read more

The fastest way to export data to Excel

Export data to Excel in ASP.NET C#
0
It is not so rare that you have to provide some sort of export of your data stored in database. I have a feeling that clients really like to have that functionality, probably because they are more comfortable with Excel than with any other tool. First thing that might pop to your mind is to add a reference to Office library, but that would require that you have Office on the hosting machine which might not be the case as most of hosts do not have it. ...read more

Simple object mapper using reflection

Copy property values from one object to another using reflection
0
Dealing with models and POCO classes in MVC sometimes require to map properties from one object to another because they have some properties of the same name and type. This also can be a case when you are loading a model class from some other source and you need to transform it to your type with some additional properties, but also a bunch of properties with values from the source object instance. ...read more

Getting cropped image the smart way

The way to get cropped image URL with option to load original image too
0
I noticed that some of the content managers keep complaining about the quality and size of cropped images. If you lower down quality, file is smaller but in some cases it gets blurry with quirks which comes from compression applied to a file. Let's face it, image cropper is not Photoshop with all options for image optimization...read more

JavaScript

read more

Umbraco CMS

read more

.NET

read more

SQL/T-SQL

read more