ZNAG - Browsing C#

  1. Java Java for a .Niet dev

    I've been hacking on a small Android application lately, which exposed me to Java.

    I've never really written an entire application in Java before, and the experience is rather interesting.

    I mainly write in C# for server side code, and although I like to learn other languages, C# still remains my favorite language.

    Java for me was very similar to C# (and ActionScript too, being yet another ECMA'ish language), and writing it was not as annoying as writing c++.

    Even though I found things missing (such as automatic getters and setters, String.IsNullOrEmpty), I was rather surprised to see how powerful Java really is.

     

    To summarize, Java should be respected. It had an amazing feature set way before C# was created (or copied and enhanced).

    That doesn't mean that I'll write applications in Java though :)

    A certain brit called Tim might be furious that someone learns Java before Scala , but that's another story..

     

    Cheers,

    Erik

    Tags: C#, Java


  2. Using Mvc user controls from another controller

    I needed to use a user control from a different controllers folder in a view.

    Should be easy I thought, there’s probably an overload for the Html.RenderPartial that with the controller name.

    Unfortunately, that’s not the case.

     

    If you look at the solution layout below:

    SolutionLayout

     

    I needed to user the “OtherControl.ascx” from the Home controllers views.

     

    Passing only the user control name to the Html.RenderPartial won’t work, and you’ll end up with an error like this:

    Error

    Which is rather logical, as that’s the default behavior of the web forms view engine.

     

    Overcoming the problem is rather strait forward :

     

    <% Html.RenderPartial("../Other/OtherControl"new string[] { "ListItem1""ListItemN" }); %>

     

    Not the most elegant solution, but it works..

     

    Demo | Source

     

    Cheers

     

    Erik

    Tags: asp.net mvc, aspnetmvc, C#


  3. ASP.NET MVC 2 Preview 1

    Phil Haack totally surprised with the announcement of the first preview release of ASP.NET MVC 2.

    I’ve been using ASP.NET MVC (1) very since the third preview was released and I’ve really enjoyed the the experience.

    IMHO, WebForms was never really fitted to the web platform, having a to complicated life cycle, and abusing the POST method in a way it was really not meant to do.

    I do think WebForms was a great way to get WinForm developers up and doing web development quickly,
    on the other hand, it grew a generation of Drag and Drop developers that had no idea what a POST really is (I know, I used to be one :D).

    One of the main problem in WebForms is that it’s simply to much magic going on. The server controls writes plenty of content to the page, and typically, the developer using the control has no idea, and/or no control of what is rendered to the page.

    For me the ASP.NET MVC brought a new fresher intention from Microsoft that I really liked.
    First, they involved the public a lot with several preview releases,
    second they embraced both concepts from other popular frameworks such as Ruby, and even bundled jQuery*!.

    This was somewhat of a mindblower for me, since it kind of ruined the typical Micro$oft big corporate image I had.

    Add to that the fact the the ASP.NET MVC framework was implemented in such an amazing way, that besides being enjoyable to develop in, felt much more correct and well suited for the web.

    The framework allowed me to program the server side code in C#, which is the language I’m most comfortable with, and supported a clean separation of markup, client side code and server side code.
    Furthermore, it was finally unit-testable!

    The ASP.NET MVC 2 looks really interesting, here’s some recommended reads:

    The fact that it’s possible to use without causing any problems with the existing MVC framework is fantastic..

    Kudos to the ASP.NET MVC team for their great efforts!

    Cheers,

    Erik

    *This was one of the reasons besides I got into jQuery more, although the credit goes to Tim Perrett for introducing jQuery to me amongst so much more ubercool stuff :D)

    Tags: aspnetmvc, C#, asp.net mvc, aspnetmvc2, asp.net mvc 2


  4. Convert Encoding Utility

    Prelude (skip):

    I had another one of those "utilicous" moments again.

    I ran into a familiar problem that I've met before:

    I had a site written in ANSI encoding (default behavior by Visual Studio BTW) , with some localized Hebrew content. The default settings if the web site in IIS were indeed ANSI for reading the files, and UTF-8 for displaying the files.
     
    Peaches, everything was working fine..
     
    Then I had to move the site to a different server..
    Suddenly my site looked like a wingdings party.
    The new server had different regional settings, and UTF-8 as the default for reading files.
    I soon realized I had to go over the entire site, saving all files to UTF-8
    (Yes, a better practice would have been to do so from the beginning, and override the default file encoding in the web.config).

    Suddenly the "utilicous" feeling was all over me again, Time for a utility!

    Thus the Convert Encoding Utility Was Born…

    Ok, so I got the idea for what was needed, a small WinForm application that'll choose a root folder, and perhaps even file extensions to modify.

    After finishing the WinForm, I got that "hmm this could be useful for others" feeling.

    After some refactoring, and I separated the solution to 3 projects:

    1. Base library

      Exposes methods that alter the file encoding either of a single file, or of a folder (with the possibility to filter by file extensions)

    2. Console application

      Uses the library above. Can get command line arguments such as single file to modify or a root directory (with the possibility to filter by file extensions)

    3. WinForm application

      Same as the console, but with UI

    If you have any problems with the utilities, code or the documentation, please report it at Issues section

    Enjoy,

    Erik

    Tags: Utilities, C#