Monday, September 30, 2013

Multiple file upload with asp.net 4.5 and Visual Studio 2012

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.

1
2
<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.

1
2
3
4
5
6
7
8
9
10
11
protected void uploadFile_Click(object sender, EventArgs e)
{
    if (multipleFile.HasFiles)
    {
        foreach(HttpPostedFile uploadedFile in multipleFile.PostedFiles)
        {
            uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Images/"),uploadedFile.FileName));
            Response.Write("File uploaded successfully");
        }
    }
}



Here in the above code you can see that I have checked whether multiple file upload control has multiple files or not and then I have save that in Images folder of web application. Once you run the application in browser it will look like following.

Multiple file upload with asp.net 4.5 and Visual Studio 2012


I have selected two files. Once I have selected and clicked on upload file button it will give message like following.

Multiple file upload with ASP.NET 4.5 and HTML5

As you can see now it has successfully upload file and you can see in windows explorer like following.

Multiple file upload ASP.NET 4.5 and Visual Studio 2012

As you can see it’s very easy to upload multiple file in ASP.NET 4.5. Stay tuned for more. Till then happy programming.

Extract to User Control in visual studio11



In large projects, we are having large pages and its always good to use  user control(.ascx) but sometimes we are so lazy to create user controls and we remain with the whole page and even we can’t reuse that code. In similar kind of situation ‘Extract to user control’ can be quite useful. Suppose we have long HTML mark up and we need to convert one div to user control and then we can do it very easily with Visual Studio 11 beta Extract to User Control feature.

You just need to select code you want there in user control and then you need to right click and click ‘Extract to User Control’ like below.

Extract to user control feature- What's new in visual studio 11 features


And once you click on ‘Extract to User Control’ It will ask to save your user control with save dialog like following.

Extract to user control feature save dialog visual studio 11 feature series

Once you click ok a new user control will be like following.

Extarct to User control- Extracted user control in visual studio 11

And now your mark up in default.aspx page will look like following.

extract to user control visual studio 11 aspx page

Dark Visual Experience in Visual Studio 2012

 I found that there are two type of themes available in visual studio 2012 light and dark under Tools->Option-> General environment value. This is one of newest feature I have found in visual studio 2012.

Dark Visual Experience in Visual studio 2012- A new visual studio feature.

Once you switch to dark and click ok. It will look like completely dark like following.

Dark Visual Studio theme like blend - A Visual Studio 2012 feature

It totally look like Expression blend and even if you open project the editor font and everything looks like same as blend.



Color indication in Visual Studio 2012

Before some days Microsoft has released the release candidate version of Visual Studio 2012. Today I got installed Visual Studio 2012 and once I loaded the visual studio 2012 first things I noticed that there is purple color blank strip is there at bottom. After doing some R and D on internet I have found that it is used for the different indication. The purple color indicates that there is no project loaded now.


Color Indication in visual studio 2012 Purple color for no project


Once you open the project this line will be of blue color like below.

Blue color for project loading in visual studio 2012 color indication feature in visual studio 2012

Once you run and F5 and debug it, the color will change to orange like below
.
Orange color in Visual Studio 2012 Indicator indicate that it is in debug mode.

Isn’t that great? A simple color indicator for each mode in visual studio 2012. Stay tuned for the more. I am going to put some more post about Visual Studio 2012. Till then happy programing

Image preview in solution explorer Visual Studio 2011 beta

Everyday I am using Microsoft Visual Studio 2011 beta and everyday I learn some cool feature of it. In today’s post I am going to explain one cool features of Visual Studio 2011 beta solution explorer. As a web developer we all want to see the image preview in solution explorer and visual studio 2011 beta is now having it. We can see image preview in solution explorer just like following.


ImagePreviewSolutionExplorer

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...