Home ASP.NETASP.NET interview questions: - Describe how can we Browse and Upload a file in ASP.NET?
This not one of those most asked ASP.NET questions , but yes sometimes interviewer starts getting in to practical things to understand how good you are as a developer.
So let’s see a small and simple example to understand it in better manner.
In order to see it practically just follow the following steps.
Step1: - create a new project of ASP.NET for that just go to >> File >> New >> Project >> Web >> select ASP.NET Empty Web Application.
Step2: - now, just simply add a Web form page in to your application for that just go to >> Solution Explorer >> Right click on the project name >> Add >> New Item >> Select Web Form.
Step3: - Now Add a FileUpload control and Button control from the ToolBox to the WebForm.aspx Page.
The WebForm.aspx page should appear like below diagram.
Step4: - Now simply just add the below code snippet in to WebForm1.aspx.cs file.
protected void Button1_Click(object sender, EventArgs e){if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0)){string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);string location = Server.MapPath("")+"\\"+filename;try{FileUpload1.PostedFile.SaveAs(location);Label2.Text="The File has been successfully uploaded";}catch (Exception ex){Label2.Text = "Error : " + ex.Message.ToString();}}else{Label2.Text = "Please Enter a File";}} The above code snippet is for the Button control for uploading the selected file to the server.
Once you have completed all the above steps just run your application to get a resultant result.
The above diagram is the running page we have created, now just click on the browse button to select a file from desired location.
Once you have selected the file now just click on the upload button.
Now if everything goes right you will see a result like below diagram.
View the following video on use of Static keyword: -
Get more learning materials for ASP.NET interview questions
Regards,
View author’s other article on ASP.NET interview questions




Write a Comment
All fields marked with * are mandatory
ASP.NET interview questions: - Can you explain Method of Sorting GridViewcontrol in ASP.NET?
Sorting allow you to sort the GridViewcontrol data in Ascending or Descending order.... Read More
By : Shiv Prasad Koirala | Aug 4th, 2011 | ASP.NET
WCF Interview questions:- Which binding do we need to use for WCF REST?
In this article we will show Binding used for WCF REST. For more articles and videos visit us on www.questpond.com... Read More
By : Shiv Prasad Koirala | Nov 16th, 2011 | WCF
.NET interview questions: - Can you elaborate project life cycle?
In this article we will explain about project life cycle. For more articles and videos visit us on http://www.questpond.com/... Read More
By : Shiv Prasad Koirala | Jan 17th, 2012 | .Net
.NET interview questions: - How will you distinguish between ForeGround and BackGround Threading?
threading is a parallel processing unit and helps you to access multiple tasks at a one moment of time.... Read More
By : Shiv Prasad Koirala | Sep 27th, 2011 | ASP.NET
C# interview questions: - Explain anonymous methods in .NET?
n simple words Anonymous Methods means method which are coded inline or methods without method name.... Read More
By : Shiv Prasad Koirala | Aug 5th, 2011 | C#
ASP.NET interview questions: - Can you explain Method of Sorting GridViewcontrol in ASP.NET?
Sorting allow you to sort the GridViewcontrol data in Ascending or Descending order.... Read More
By : Shiv Prasad Koirala | Aug 4th, 2011 | ASP.NET
WCF Interview questions:- Which binding do we need to use for WCF REST?
In this article we will show Binding used for WCF REST. For more articles and videos visit us on www.questpond.com... Read More
By : Shiv Prasad Koirala | Nov 16th, 2011 | WCF
.NET interview questions: - Can you elaborate project life cycle?
In this article we will explain about project life cycle. For more articles and videos visit us on http://www.questpond.com/... Read More
By : Shiv Prasad Koirala | Jan 17th, 2012 | .Net
.NET interview questions: - How will you distinguish between ForeGround and BackGround Threading?
threading is a parallel processing unit and helps you to access multiple tasks at a one moment of time.... Read More
By : Shiv Prasad Koirala | Sep 27th, 2011 | ASP.NET
C# interview questions: - Explain anonymous methods in .NET?
n simple words Anonymous Methods means method which are coded inline or methods without method name.... Read More
By : Shiv Prasad Koirala | Aug 5th, 2011 | C#
Article Categories
YouTube Videos