.Net Interview Questions and Answers

Search:

ASP.NET interview questions: - Describe how can we Browse and Upload a file in ASP.NET?

By : Shiv Prasad Koirala | Sep 28th, 2011 | Views : 167 | Comments : 0 Bookmark and Share
 

    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
    
    
    
 

 
Rate this Article :
1 Star
2 Stars
3 Stars
4 Stars
5 Stars
0 1 1 2 1
 
 
Comments

Write a Comment

All fields marked with * are mandatory

cd1ea

 

 

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

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

.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

.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

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

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

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

.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

.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

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

Article Categories