Archives

Archives / 2010 / July
  • What is ForkCan.com – Do you have what it takes to Share your code?

    I have worked on a project for a while now, I call it ForkCan and can be found on the following URL www.forkcan.com. ForkCan is all about sharing code in a social way. I have notice that several developers on twitter paste pointers to sites like paste-it.net to share some code with others, and to get feedback on the code. I moved this a little bit further and created a similar site BUT! I also want to make sure developers can learn from each other, discuss the code with each other and much more. There are so many great code examples shared and distributed on the web, but to find them we need to search for it and it’s spread around different blog posts, forums etc. I wanted to create one place where developers can add the code, make a repository of codes where everyone can find great code to be used in a project. I also created ForkCan to save my own “good to have” code snippets, so I can find it easy and and copy and paste it into my projects. You may wonder why I call it ForkCan? It’s because it can be used as a can of forks ;) Fork in Software development is about taking an existing code and make development on it. So with ForkCan you can share your code, someone else can make it even better by making a Fork of it. The idea of ForkCan is to help each other to be better developers. The site also is a great tool for the Copy & Pasters.. ;)

    Read more...

  • Microsoft WebMatrix – Easy way to build ASP.NET Web Sites

    Yesterday Microsoft announced WebMatrix, a tool to build standalone ASP.NET Pages using the new Razor view eninge. With WebMatrix developers will get the new IIS Developer Express and SQL Compact Edtition.

    The idea of WebMatrix is to make it easy for developers to build web sites, not yet suitable for Enterprise Apps in my opinion, more for devs that want to get started really fast. With WebMatrix we will get a tool to easily create a Site, Browse our files, manages our database etc:

    image

    The tool is easy to use, easy to learn and manage. You don’t need to have Visual Studio to create a simple ASP.NET website. The following is an image editing a file within the tool:

    image


    Razor is a new View engine which can be used to write ASP.NET Web pages, the "Razor" view engine together with WebMatrix reminds me a lot about classic ASP pages but using .Net, something that I like. It will make it much easier for those devs that find it hard to move from classic ASP to ASP.Net. Here is an example why I think WebMatrix and "Razor" reminds me of classic ASP pages, the code will read from a database and list members that belongs to a specific group, the value of the group is taken from the QueryString “group” by using the Request helper method:

    @{
       string group = Request[“group”];
       var db = Database.Open("Members");
       var members = db.Query("SELECT * FROM Members WHERE Group = @0", group);
    }
    
    <html>
          <head>
                   <title>List members</title>
          </head>
          <body>
                    <ul>
                       @foreach (var member in members) {
                          <li>@member.FirstName - @member.LastName</li>
                        }
                     </ul>
          </body>
    </html>

    I like this way of writing a small app and the Razor’s much cleaner syntax. Have in mind that Razor view engine with ASP.NET MVC can be used for enterprise apps. Using Razor with WebMatrix will not target entperise apps developers in first place.

    Handling “submit “ HTTP Post and also caching is quite easy. To check if a Post is made, we can use the IsPost property, to cache information we can use the WebCache helper, the following is just a fast example I put together to demonstrate the use of IsPost and WebCache helper,

    @{
    
         var minutesToCache = 10;
         var useSliding = true;
         string data = string.Empty;
    
         if(IsPost)
         {
               data = Request["myData"];
    
               if (WebCache.Get("Key") == null)           
                    WebChache.Set("Key", data, minutesToCache, useSliding);
         }
    
        if(WebCache.Get("Key") != null)
              data = WebCache.Get("Key").ToString();
     }
    
    <html>
          <form ..>
               <input type="text" name="myData" value="@data" .../>
               <input type="Submit" ..../>
          </form>
    </html>

    With Razor we will get some social Web Helpers, for example Twitter, Gavatar etc:

    <body>
          @Twitter.Search("WebMatrix")
    </body>

    We can also an easy way create Code-based helper method, Microsoft is looking for supporting HTML Helpers, to globally share helpers among pages. Here is an example of a HTML Helper (will not work in the beta):

    @helper RenderMembers(List<Member> members) {
       <ul>
          @foreach (var member in members) {
            <li>@member.FirstName @member.LastName</li>
          }
       </ul>
    }
    
    
    <body>
        @RenberMembers(Model.Menbers)
    </body>

    If you want to know when I have published a new blog post, follow me on twitter: fredrikn

    Read more...