Saturday, July 28, 2012

Multiple file upload with mvc and HTML5

Few days I have written a blog post about Multiple file upload with 4.5 and Visual studio 2012. It was greatly appreciated by the community and also been part of community daily spot light.  On that post one of my reader Ciwan Kurd has requested the mvc version of that post. So in this post I will explain how we can do multiple file upload with HTML5.

For this post I am going to use mvc 3 with HTML5 template and visual studio 2012 but you can use same techniques in any version of mvc.  First things we needs to do create a HTML form for the uploading file in mvc view so following is a code for that.

@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
    <label for="file">Upload Image:</label>
    <input type="file" name="files" value="" multiple="multiple"/>
    <input type="submit" value="Upload Image" />

In above code that I have use @HTML.BeginForm to create a HTML form with multipart as this attribute is required to upload any kind of files on the server. I have mapped that form to upload action result. Also I have used the file input control with HTML5 multiple attribute which allow us to upload multiple files on the server. Now its time to write code in mvc controller. Following is a code for that.
Tuesday, July 17, 2012

Why we should write blogs and do community work

I am doing blogging since last 5 years and I have seen lots of people asking the same things. Why do you write blog? do you have any side income for this blog? Why you are so active in community ? I am answering this questions almost every day. So I decided to write a blog post about it. Following are the reason why I am writing blogs and doing community work?


I like to help people and that is one of the main reason behind the all blogs and community work. Also helping other is a great way to learn new things. Because other person may be facing a problem which you never encountered during your professional life or project you are doing!!. At the end of you can feel proud that you help somebody.


I have to learn lots of things everyday to write my blogs. Some one said Teaching some one is best way to learn new things. It apply here also when you write blog or answer question on forum.

Earn Award and Get famous:

This is one of the advantages of writing blogs and doing community things. People will know that you are having such knowledge in respected fields. I have got Microsoft Most Valuable Professional award 3 times due to my blogging and community work. But remember one thing your first intension of doing communication work is to help people. All other things will come as other benefits.

Communication skills:

Once you communicate with lots of people and write blog it will definitely increase your communication skills. If you are writing some blogs then its going to increase your writing skills also.

Model binding with ASP.NET 4.5 and Visual Studio 2012

Note:I have written a whole series of Visual Studio 2012 features and this post will also be part of same series. You can get the whole list of blogs/articles from the Visual studio 2012 feature series posts there. Following is a link for that.Visual Studio 2012 feature series
In earlier version of the we have to bind controls with data source control like SQL Data source, Entity Data Source, Linq Data Source if we want to bind our server controls declaratively. Some developers prefer to write whole data access logic and then bind the data source with databind method. Model binding is something similar to mvc binding.

Model Binding in ASP.NET 4.5 and Visual Studio 2012:

With ASP.NET 4.5 and Visual studio 2012 we have a new method of binding data called ‘ Model binding’. It’s a code focus approach of data binding. Now all the controls will have ItemType property which will implement strongly type binding. The server controls will then call appropriate methods at the proper time in page life cycle and bind the data.

So what we are waiting for ? let’s take one example. First we need to create a model. For the this I have created a model class called ‘Customer’. Following is code for that.
Thursday, July 12, 2012

Free Visual Studio 2012 eBook from Telerik

Note:I have been writing lots of things about Visual Studio 2012 and this post is same in the series. You can find complete list of post from the following link.Visual Studio 2012 feature series- What’s new in Visual Studio 2012.
Visual studio 2012 is there in RC stage and I am exploring that into the great extent. Visual Studio 2012 is great editor there is no doubt. It is much more mature and comes with lots of features. Telerik – A well know in third party controls released a free eBook on Visual Studio 2012 and ASP.NET 4.5. You can find lots of time saving feature documented in this eBook.

Visual Studio 2012 feature list - What's new in Visual Studio 2012

Following is a quick list of features they have explored in Visual Studio 2012.
  1. JavaScript Intellisense
  2. CSS Intellisense
  3. ASP.NET and ASP.NET Web API
  4. Strongly typed data binding
  5. Page Inspector(new Debugging Tool)
  6. HTML5 and CSS3 is available out of box
  7. Request validation prevents yellow screen of death
  8. WAI Aria makes the web usable by all
Saturday, July 7, 2012

Dividing web.config into multiple files in

When you are having different people working on one project remotely you will get some problem with web.config, as everybody was having different version of web.config. So at that time once you check in your web.config with your latest changes the other people have to get latest that web.config and made some specific changes as per their local environment. Most of people who have worked things from remotely has faced that problem. I think most common example would be connection string and app settings changes.

For this kind of situation this will be a best solution. We can divide particular section of web.config into the multiple files. For example we could have separate ConnectionStrings.config file for connection strings and AppSettings.config file for app settings file.

Most of people does not know that there is attribute called ‘configSource’ where we can  define the path of external config file and it will load that section from that external file. Just like below.

 <appSettings configSource="AppSettings.config"/>
 <connectionStrings configSource="ConnectionStrings.config"/>

And you could have your ConnectionStrings.config file like following.
Tuesday, July 3, 2012

Event handler generation in Visual Studio 2012

Note: This post will be a part of Visual Studio 2012 feature series.
There are lots of new features there in visual studio 2012. Event handler generation is one of them. In earlier version of visual studio there was no way to create event handler from source view directly.  Now visual studio 2012 have event handler generation functionality.

So if you are editing an event view in source view intellisense will display add new event handler template and once you click on it. It will create a new event handler in the cs file. It will also put a eventhandler name against event name so you don’t need to write that.

So, let’s take a simple example of button click event so once I write onclick attribute their smart intellisense will pop up
Event handler generation in visual studio 2012 - What's new in visual studio 2012

Now once you click on <Create New Event> It will create event handler in .cs file like following.
Monday, July 2, 2012

Multiple file upload with 4.5 and Visual Studio 2012

Note: This post will be part of Visual Studio 2012 feature series.
In earlier version of ASP.NET there is no way to upload multiple files at same time. We need to use third party control or we need to create custom control for that. But with 4.5 now its possible to upload multiple file with file upload control.

With ASP.NET 4.5 version Microsoft has enhanced file upload control to support HTML5 multiple attribute. There is a property called ‘AllowedMultiple’ to support that attribute and with that you can easily upload the file. So what we are waiting for!! It’s time to create one example.
On the default.aspx file I have written following.

<asp:FileUpload ID="multipleFile" runat="server" AllowMultiple="true" />
<asp:Button ID="uploadFile" runat="server" Text="Upload files" onclick="uploadFile_Click"/>

Here you can see that I have given file upload control id as multipleFile and I have set AllowMultiple file to true. I have also taken one button for uploading file.For this example I am going to upload file in images folder. As you can see I have also attached event handler for button’s click event. So it’s time to write server side code for this. Following code is for the server side.

protected void uploadFile_Click(object sender, EventArgs e)
    if (multipleFile.HasFiles)
        foreach(HttpPostedFile uploadedFile in multipleFile.PostedFiles)
            Response.Write("File uploaded successfully");

Sunday, July 1, 2012

Third year in a row- Microsoft MVP again!!

Today is Sunday and I was not expecting this as today is holiday although I know it was Microsoft Mvp renewal day. At evening I got the congratulation email from the Microsoft. Yeah!! I am Microsoft Most Valuable Professional again. I got the same message as a part of Mvp. Thanks Microsoft again.

Dear Jalpesh Vadgama,
Congratulations! We are pleased to present you with the 2012 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in Visual C# technical communities during the past year.

Feeling is again same as first time. I am going to dedicated this award to my family. My parents who always inspired me to do new things. My wife who scarifies her time to write blogs. My brother who support me in every possible way.

On this occasion, I would also like to thanks my reader without their support it was no possible to achieve this. Thanks for reading my blog!!. Please do keep reading this.
I will try to write as much as possible.

I would also like to thanks ‘Tanmay Kapoor’ My Mvp lead for continuous support. 


Quick tour of visual studio 2012 features so far

Note: I am writing a whole new feature series about Visual Studio 2012 new features. Following is the link for that. I have written couple of post there.Visual Studio 2012 features series. What's new in Visual Studio 2012
I thought it would be great idea to write summary post for this. So this post will be a summary of all the post I have written so far. Here it will describes what’s new in visual studio 2012 and what are the features that I have covered so far. It will be quick of tour of some of the feature in Visual Studio 2012.

Visual studio 2012 first review(Earlier known as Visual studio 2011 beta)

In this post, I have written about the Metro UI of visual studio 2012. It’s totally different then the older version of visual studio 2012. Now its empathize more on code instead of visual appealing things. In this blog post I have also described solution explorer and tool box features also. Following is a link for that.

Visual Studio 2011 Beta First Review(Now known as Visual Studio 2012)

Project dialog box changes in visual studio 2012

In this post, I have written about Project dialog box changes and also written about new project templates which are included in the project dialog like ‘Portable Class Library’. I have also explained some of new other additions in project template like ‘Light switch category’ and ‘Coded UI test project’ in visual studio 2012. Following is a link for that post.
Search This Blog
About Me
My Photo

Full Stack Developer,Blogger,Microsoft Mvp, Mentor, Life long learner, 10+ Years of Experience for JavaScript, web and Microsoft technologies. ASP.NET MVC,Web Forms,C#,AngularJs,Golang
Mvp profile
Subscribe to my blog

Enter your email address:

Follow us on facebook
Blog Archive
Total Pageviews