When you have a list of strings like IList<string> of IEnumerable<string> and you want to convert it to for example a comma separated list you can easily do that with the String.Join method.
List<string> list = new List<string>() { "A" , "B", "C", "D", "E" };
string commaSeparated = String.Join(",", list.ToArray());
The output will be like this:
This is an easy and clean way to create a delimiter separeated list of strings.
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.

Today 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.
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.
Last week I have seen a Demo about Umbraco, the demo was given by Richard Soeteman from Soetemansoftware an experienced Umbraco developer.
Umbraco is a CMS that fully integrated with .NET, it’s supports .NET out of the out-of-the-box, you can use .NET Custom Controls and .NET User Controls without extra effort. You can place your controls everywhere in the template and even in the rich text editor, Umbraco can also send data to your controls via Public Properties. Umbraco is fully compatible with ASP.NET Ajax and javascript frameworks like jQuery and prototype.
The templates in Umbraco are build with XSLT, with XSLT so you are very flexible to create your html. Umbraco supports also XSLT extension methods, so when you miss some functionality in XSLT you can create methods it in .NET and call them from your XSLT templates.
What’s also great about Umbraco is the event model, you can hook up at a lot of events and create your own logic. Hooking into these events is simply a matter of creating a .NET class that implements an interface.
What i haven’t mentioned yet is that Umbraco is licensed under the MIT license, so you can see and modify all the source code, but isn’t likely that you will change the source because it support mostly all features that are needed.
Richard Soeteman have given us Demo that includes most of aspects of Umbraco. First we did the installation of Umbraco. It’s very easy to install Umbraco, you only have to unzip Umbraco to the wwwroot and request the website and follow the configuration wizard. You can start with a empty Umbraco or with a starter kit.
In the demo we started with the starter kit Umbraco installation and we added also some packages that are needed for the demo, we modified some templates and created some usercontrols in Visual Studio and added them to Umbraco.
With this demo I get a good impression about Umbraco, Umbraco is very easy to use and to implement. So if your are searching for a open source .NET CMS, try it out at umbraco.org
Today I was adding a webservice via "Add Web Reference" to my project. The webservice was only accessible on https with a client certificate. When I did "Add Web Reference" I got a "The underlying connection was closed: Could not establish secure channel for SSL/TLS", but in IE it's works perfect. After some research I found an other way to add the webservice via "Add Web Reference". You can do it like this:
- Save the WSDL to a location on your machine.
- Copy the path.
- Go to the Add Web Reference in your project.
- Paste the path you copied into the URL.
- Click on Go.
- Click on Add Reference
Don't forget to change the webservice url in your Web.config or App.config.
A common task in a project is preparing your for a deployment. The easiest way to do this is making use of a Web Setup Project. But how do we make this Web Setup Project suitable for multiple environments, because it's most likely that there are environments like Development, Test, Acceptance and Production.
The key to this solution is the "Condition" property. If you add a file to the Web Setup Project (In the File System view right mouse button on the Web Application Folder, then Add -> File) and select it you can find the "Condition" property in the properties window.
We add the following value to the "Condition" property ENV="Prod", this is for the production environment, for the test environment it will be something like this ENV="Test".
We also set the "TargetName" propery to Web.Config so the Web Setup Project will output the configuration file as Web.Config.
Well you can add unlimited Web.Config files to your Web Setup Project, they are all output as Web.Config but not all at the same time. So how can we choose the correct Web.Config for your environment, well like this:
%windir%\system32\msiexec.exe /i "Setup.msi" ENV="Prod"
- msiexec.exe (the Windows installer)
- /i (is the install switch)
- "Setup.msi" (compiled output of the Web Setup Project)
- ENV="Prod" (the condition value).
If you run this the setup will be started, after the setup is finished you will notice that only the Web.Config is installed with the "Condition" property set to ENV="Prod".
To make this all fool proof you can make a shortcut to this command line, like this:
Now when you click on this shortcut you get the same result.
So with this solution you can make one Web Setup Project for all your environments and create a better and stable deployment solution.
Yesterday jQuery released their new version, number 1.3. They did a lot af changes / bugfixing, performance improvements.
The big features are:
- Sizzle: A sizzlin’ hot CSS selector engine.
- Live Events: Event delegation with a jQuery twist.
- jQuery Event Overhaul: Completely rewired to simplify event handling.
- HTML Injection Rewrite: Lightning-fast HTML appending.
- Offset Rewrite: Super-quick position calculation.
- No More Browser Sniffing: Using feature detection to help jQuery last for many more years to come.
They did a pretty good job on the performance:
Selector performance, 49% faster:
Delegation filtering performance, 30x times faster:
Element insertion performance, 6x faster:
Offset rewrite, 3x times faster:
There is also a new API browser released with the following features:
- All the latest jQuery and jQuery UI documentation.
- The ability to mark pages as favorites for those pages you keep wanting to return to.
- Syntax highlighting in the code examples
- Live running of examples within the browser
- Links to edit and experiment with the code examples
You can find it here:
http://api.jquery.com/
The new version you can download here:
Downloading jQuery
Or you can use the google hosted version:
Google AJAX Libraries API
More info:
Blog: jQuery 1.3 and the jQuery foundation
Release notes
Most people use alert() to debug their JavaScript, but the Microsoft Ajax Library has a better alterative Sys.Debug. Sys.Debug has some methods for logging messages to the browser console. Like this:
To log a message:
Sys.Debug.trace(“Log to the console”)
To log an object:
Sys.Debug.traceDump(someObject);
You can use Web Development Helper for IE, and Firebug for Firefox to see your console messages. Or use textarea element with the id "TraceConsole" to trace your messages:
<textarea id=”TraceConsole” rows=”50” cols=”50”></textarea>
From:
http://weblogs.asp.net/alnurismail/archive/2009/01/12/a-better-alternative-to-using-alert-for-debugging.aspx
More and more ASP.NET developers are going to use jQuery. jQuery is a fast and easy to use javascript framework.
On the tvi design blog a nice article has been posted with some very excellent tips how to improve your jQuery. All tips are very useful and gives you easy improvements, so take a look!
More Posts
Next page »