2 posts

Sample ASP.Net MVC project (updated)

I’ve updated the sample MVC project I wrote for using ASP.NET MVC 3 and the Razor view engine.

A minor change is that I no longer use the FluentValidationModelValidatorProvider but the standard one. So I decorate the view model with the necessary data annotations :

public class UserViewModel
    public int Id { get; set; }

    [DisplayName("First name *")]
    public string FirstName { get; set; }

    [DisplayName("Last name *")]
    public string LastName { get; set; }

    public int? Age { get; set; }

Continue reading

Uploading multiple files with C#

Have you ever been in a situation where you needed to upload multiple files to a remote host and pass additional parameters in the request? Unfortunately there’s nothing in the BCL that allows us to achieve this out of the box.

We have the UploadFile method but it is restricted to a single file and doesn’t allow us to pass any additional parameters. So let’s go ahead and write such method. The important part is that this method must comply with RFC 1867 so that the remote web server can successfully parse the information.

First we define a model representing a single file to be uploaded:

public class UploadFile
        public UploadFile()
            ContentType = "application/octet-stream";
        public string Name { get; set; }
        public string Filename { get; set; }
        public string ContentType { get; set; }
        public Stream Stream { get; set; }

Continue reading