Chanel 9 | Rx Workshop: Unified Programming Model

Posted August 2nd, 2011 in .NET, Quick posts, Reminders by admin

Learn how to wrap existing event sources, including tasks, asynchronous methods, .NET events, etc. in observable sequences.

ASP.NET videos : Choosing the Right Programming Model

Posted June 12th, 2011 in .NET, ASP.NET by Sam Beauvois

As mentioned by Kris van der Mast on the asp.net forums, this video was on the get started page before, but don’t appears to be there anymore.

This video is great to know in 5 minutes which model is good for you.

So, because I don’t want to search for it, I post this video here :

Install Silverlight

(direct link)

One line how to’s : Save text in a file, or read text from a file.

Posted June 12th, 2011 in .NET, HowTo by Sam Beauvois

Sometimes your solution lies in a single line.

How to save a string in a text file


System.IO.File.WriteAllText("c://yourfile.txt",
"here is the content of my file !");

How to read a text file


string content =  System.IO.File.ReadAllText("c://yourfile.txt");
How does it work ?

A bit or Reflector gives us :

For the write method


public static void WriteAllText(string path, string contents)
{
if (path == null)
{
throw new ArgumentNullException("path");
}
if (path.Length == 0)
{
throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
}
InternalWriteAllText(path, contents, StreamWriter.UTF8NoBOM);
}

and the “InternalWriteAllText” method :


private static void InternalWriteAllText(string path, string contents, Encoding encoding)
{
using (StreamWriter writer = new StreamWriter(path, false, encoding))
{
writer.Write(contents);
}
}

For the Read method :

public static string ReadAllText(string path)
{
    if (path == null)
    {
        throw new ArgumentNullException("path");
    }
    if (path.Length == 0)
    {
        throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
    }
    return InternalReadAllText(path, Encoding.UTF8);
}

And the “InternalReadAllText” :

private static string InternalReadAllText(string path, Encoding encoding)
{
    using (StreamReader reader = new StreamReader(path, encoding))
    {
        return reader.ReadToEnd();
    }
}

As you can see it don’t check if the file exists, so you have to check it by yourself :


if (System.IO.File.Exists("your file path"))
{
string content = System.IO.File.ReadAllText("your file path");
}
public static string ReadAllText(string path) { if (path == null) { throw new ArgumentNullException(“path”); } if (path.Length == 0) { throw new ArgumentException(Environment.GetResourceString(“Argument_EmptyPath”)); } return InternalReadAllText(path, Encoding.UTF8); }

6+ sources of videocasts

Posted March 3rd, 2011 in .NET, Resources by admin

Here is a list of sites where you can find videos to form youself and learn a bit of new things