Microsoft SDK for Facebook Platform

Microsoft has just released a new SDK, which aims to empower the social networking development. This SDK combines the power of Web, client and social technologies to enable developers to spread their creativity. No matter what your application flavor is, the Microsoft SDK for Facebook Platform supports the development of applications across Silverlight, WPF, ASP.NET, ASP.NET MVC, and Windows Forms, enabling easy consumption of Facebook services delivered through the Facebook Open Stream API.

To get started you have to download the SDK and refer to the “How to” guides and the Facebook Developer Wiki to get familiar with these new resources.

  1. Download the SDK.
  2. Refer to the detailed instructions on the Facebook Developer Wiki. Here are some important links to use as a starting point.

Read more at the official site of the SDK.

Filled under Social Networking. No Comments.

Capture the HTML output from a custom server control in ASP.NET

Custom server controls do great job. A complex page can easily be split into many controls. In this way it becomes easier to support after that. Used in a page, a server control follows the whole page life cycle.

Sometimes you will need just to get the HTML output from a server control for a different usage like sending it by an e-mail. So what can you do?  There is a method called RenderControl, which renders a control using a HtmlTextWriter object. We can simply load the control using the LoadControl method and then use RenderControl.

Control myControl = LoadControl("~/MyControl.ascx");
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter(sb))
{
	using (HtmlTextWriter tw = new HtmlTextWriter(sw))
	{
		myControl.RenderControl(tw);
	}
}
Console.WriteLine(sb);

But the output is not what we really want. It contains only the static HTML tags. The server controls inside our control are not rendered. Why? Because in our way, the control does not follow the page life cycle. So, what we should do is to add it to a page.

Page page = new Page();
Control myControl = LoadControl("~/MyControl.ascx");
StringBuilder sb = new StringBuilder();
 
page.Controls.Add(myControl);
 
using (StringWriter sw = new StringWriter(sb))
{
	Server.Execute(page, sw, false);
}
 
Console.WriteLine(sb);

Server.Execute method executes an IHttpHandler object and writes the output using a TextWriter object. In this way we follow the whole page life cycle so our control will render everything inside it.

Filled under ASP.NET. No Comments.

Crack .NET

New great debugging tool has come to the web. Crack .NET allows you to go through the managed heap of your Windows Desktop application (Windows Forms or WPF) and see what it contains. Not only you can see what’s inside, but you can modify it using IronPython scripts.

Crack .NET

(more…)

Filled under C#, News. No Comments.

Silverlight Write & Win Contest

Silverlight 2 ContestSilverlight Write & Win Contest was carried out for the second time. It is a interesting contest. You only have to write an article about Silverlight (application, control, game, web services, Blend, design, example, problem solution, etc). The first contest was organized by Michael Sync. Now, SilverlightShow take this initiative. They really did a great job in the organization.

I took part in the first edition, so I decided to write an article for this one, too. And I got it! I won the third prize, which looks like this:

  • Telerik – RadControls for ASP.NET AJAX Developer Subscription and Source Code License ($999 value). This license includes all 23 Telerik ASP.NET AJAX controls, a Gold Support Package and free product updates for a period of one year. The winners will also receive complimentary licenses for Telerik RadControls for Silverlight
  • SilverlightShow – $100 in Amazon Gift certificate or cache

Cool, right? The one who get the first prize is Alexey Zakharov with his article – Virtual earth deep zooming.

SilverlightShow announced that they intend to organize another contest, so I am waiting for it.

Filled under News, Silverlight. No Comments.

StyleCop

Every programming language has its own coding style. It is very essential that every developer, who uses the language, keeps to its style. When a team of developers work over a project, they should be able to read easily the code written by everyone in the team. It does make sense how the code is written!

Here are some coding rules, when using C#:

  • Avoid writing very long methods. A method should typically have 1~25 lines of code. If a method has more than 25 lines of code, you must consider re factoring into separate methods.
  • Use String.Empty instead of “”

    Good:

    if (name == String.Empty) { // do something }

    Bad:

    if (name == "") { // do something }
  • Convert strings to lowercase or upper case before comparing. This will ensure the string will match even if the string being compared has a different case.
    if (name.ToLower() == "john") { //… }

StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. Don’t hesitate and download this great tool!

Filled under C#. No Comments.