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.



Kubernetes

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