---
title: "File Uploading in ASP.NET"  
description: "This blog talks about File Uploading  in ASP.NET.  The  fileUpload  control allows the users to browse  for and select the file to be uploaded,  provi"  
author: "priyanka kushwaha"  
published: 2015-02-17  
updated: 2015-02-17  
canonical: https://www.mindstick.com/blog/767/file-uploading-in-asp-dot-net  
category: ".net"  
tags: ["c#", "asp.net"]  
reading_time: 2 minutes  

---

# File Uploading in ASP.NET

This blog talks about File Uploading in ASP.NET.\

The [fileUpload](https://www.mindstick.com/forum/428/is-there-a-way-to-check-fileupload-has-file-or-not-in-client-side-if-it-has-i-want-to-enable-button) [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control) allows the users to browse for and [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) the file to be uploaded, providing a browse [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) and a text box for entering the [filename](https://www.mindstick.com/interview/23463/difference-between-include-filename-and-include-filename).

##### Syntax of fileupload:

<asp:FileUpload ID=”Uploader” runat=”[server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over)”>

##### Properties Description

FileBytes Returns an array of the bytes in a file to be uploaded.

\
FileContent Returns the [stream](https://yourviews.mindstick.com/view/88509/us-intercepts-iranian-tanker-m-t-stream-amid-hormuz-tensions) object pointing to the file to be Uploaded.

FileName Returns the name of the file to be [upload](https://www.mindstick.com/forum/12860/how-to-upload-file-asynchronously-using-generic-handler).

HasFile Specifies whether the control has a file to upload.

PostFile Returns a [reference](https://www.mindstick.com/forum/774/reference-what-does-this-error-mean-in-php) to the [uploaded file](https://www.mindstick.com/forum/137/how-to-check-uploaded-file-type-using-asp-dot-net).

\
Example

```
protected void bntUpload_Click(object sender, EventArgs e)    {        string res = string.Empty;        if (browserFile.HasFile)        {           try            {                String FileExtension = System.IO.Path.GetExtension(browserFile.FileName);                if (FileExtension == ".xml")                {                    if (browserFile.PostedFile.ContentLength < 262144)                    {                        string fileName = browserFile.FileName.ToString();                        string uploadFolderPath = "~/XMLFiles/";                        string filePath = HttpContext.Current.Server.MapPath(uploadFolderPath);                        browserFile.SaveAs(filePath + "\\"  + fileName);                        objClassFile.UploadXmlFile(out res, fileName);                        lblMsg.Text = res;                        listBoxEmpId.Items.Clear();                        bindDataList();                                          }                    else                        lblMsg.Text = "Upload status: The file has to be less than 256 kb!";                }                else                    lblMsg.Text = "Upload status: Only XML files are accepted!";            }            catch (Exception ex)            {                lblMsg.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;            }        }        else            lblMsg.Text = "Please select Data XML file";    }}
```

---

Original Source: https://www.mindstick.com/blog/767/file-uploading-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
