Erwin's Blog

Developing with .NET

May 2009 - Posts

DevDays ‘09 The Netherlands day #2

The second day of DevDays and 5 more interesting sessions to follow.

At 9:15 the first session of this day started it called “Functional Programming in C#” from Oliver Sturm. In this session we dived deep in to C# with a lot of C# 3.5 LINQ and lambda expressions. The question was, why would we use functional programming in C#, the answer was given with some practical examples.

The second session of today was about “Building RESTful services with the ADO.NET Data Services “given by Jurgen Postelmans. ADO.NET Data Services is build on top of the Web Programming Model of WCF. In this session we find out how easily it is to create and consume REST data services on the web. In a few minutes you can create a service that exposed your data to the web.

A funny and cool session was the third session of today, “Make Yourself Rich with XNA” from Rob Miles. He shows us in a funny way how you easily create a game in XNA. He uses the PC and a xbox controller to control the game, he also deployed the game on a Zune player. In the session we build a pong game from scratch that can be controlled with the wireless xbox controller, it was surprisingly easy to create. Oh and I think I should mention his book ;-).

The fourth session of today “IE8 and Web Standards” given by Peter-Paul Koch. What is the purpose of using web standards of today? He gives some examples how to implement the W3C web standards and give some tips and tricks. He also talked about the new IE8 browser from Microsoft and how it implements the web standards.

Last and fifth session of today in the great hall (with great chairs, i needed that after this long day) about “ASP.NET MVC Introduction” from Fritz Onion. This talk was about the ASP.NET MVC framework, he talked about the differences between typical ASP.NET applications and the ASP.NET MVC application. How do we use models, views and controllers to create a functional web application and what advantages does this model offer over the standard web forms model?

After this long day DevDays ‘09 came to an end, it was very interesting to attend all these sessions.

DevDays ‘09 The Netherlands day #1
logoToday was the first day of DevDays ‘09 in the World Forum in The Hague city. There are around 80 sessions in these two days, from cloud computing, .NET, Ajax to Silverlight and a lot more subjects.

The first sessions of today was the key note session with David Chappel, the talk was about Microsoft's cloud computing platform Azure. He told us what this new technology means and what it can do, like how do we use it in practice. The technologies that came by are Windows Azure, .NET Services and SQL services. He also mentioned some alternatives like Amazone  EC2, Google Appengine and Salesforce Platform.

The second talk I went to was C# 4.0 and the Future of C# from Krishnan Subramanian, in a very packed hall he talked about dynamic & functional languages and concurrent programming. Some topics where dynamically typed objects, optional and named parameters, improved to COM interoperability and co and contra-variance. He also talked about the future of C# and gives use some cool demo’s about on the fly compiling and running of C# code.

The third talk was about attack and defense and securing ASP.NET applications from Keith Brown, after some very nice yo-yo tricks Keith talked about how-to secure our Web applications from potential hackers. The topics that came along are server side validation, user rights, filtering, SQL injection and XSS. He also showed us how easy it was to hack a product database search web application with SQL injection if you doesn’t use parameterized queries.

In forth and last talk Fritz Onion talked about ASP.NET AJAX 4.0. How do we improve our client-side development experience this was the main subject of the talk. The talk covers subjects like the new client-side template and data binding model, declarative control instantiation, the new DataView control, markup extensions, and bindings. With ASP.NET AJAX 4.0 we can faster build quickly responding web application without creating a lot of client side code your self.

The event is very well organized at a nice location, tomorrow day two with a lot of new interesting sessions.

Convert string to byte array and byte array to string

How do we convert a string to a byte array (byte[]) and the other way around. The most simple way to do this is with the Encoding class:

String to bytes:
byte[] bytes = Encoding.UTF8.GetBytes("foo");

Bytes to string:
string foo = Encoding.ASCII.GetString(bytes);

But what if you don’t know the encoding type? Well you can use the following code snippet to change the string to byte array and byte array to string:

String to bytes:
   1:  public static byte[] ConvertStringToBytes(string input)
   2:  {
   3:    MemoryStream stream = new MemoryStream();
   4:    
   5:    using (StreamWriter writer = new StreamWriter(stream))
   6:    {
   7:      writer.Write(input);
   8:      writer.Flush();
   9:    }
  10:   
  11:    return stream.ToArray();
  12:  }

Bytes to string:
   1:  public static string ConvertBytesToString(byte[] bytes)
   2:  {
   3:    string output = String.Empty;
   4:   
   5:    MemoryStream stream = new MemoryStream(bytes);
   6:    stream.Position = 0;
   7:   
   8:    using (StreamReader reader = new StreamReader(stream))
   9:    {
  10:      output = reader.ReadToEnd();
  11:    }
  12:   
  13:    return output;
  14:  }
 
With this snippets you can convert if you don’t know the encoding of a certain string.
Posted: May 01 2009, 12:19 PM by erwin21 | with 2 comment(s)
Filed under: , ,
More Posts