Introduction
In this article we will upload files using FileUpload Control and perform download and delete operations using Link Button.
Asp.Net C# provides a file upload toolbox for upload functionality.
Let's start with the output of File Upload Control.
Prerequisites
Visual Studio 2010 or above (I used Visual Studio 2017).
In this article we will learn how to upload, download, and delete data to a web server in ASP. Net C# using File Upload Control and Display in Gridview.
Step 1
Launch/Open Visual Studio -> Go to File Menu -> New -> Project.
Step 2
Select Visual C# from left side template then choose web -> ASP.Net web application and name it then click on Ok -> Select Empty tempate -> click on Ok.

Step 3
Right Click on Solution Explorer -> Add -> New Folder -> Rename New Folder to "Uploads".

Step 4
Right click on Solution Explorer -> Add -> New Item .

Step 5
Select Web Form-> Click on Add.

Step 6
Open FileGrid.aspx File and drag out file upload control, button and gridview from Toolbar in FileGrid.aspx

Step 7
In fileGrid.aspx write the following code.
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FileGrid.aspx.cs" Inherits="FileUploading.FileGrid" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div class="container">
- <div class="page-header">
- <h3>File Uploading in ASP.NET</h3>
- </div>
- </div>
- <table>
- <thead>
- <tr>
- <th> </th>
- <th> </th>
- <th><asp:FileUpload ID="myFile" runat="server" CssClass="btn btn-warning" /></th>
- <th> </th>
- <th><asp:Button ID="btnUpload" Text="upload" runat="server" CssClass="btn btn-success" OnClick="uploadData"/></th>
- </tr>
- </thead>
- </table>
- <hr />
- <div>
- <asp:GridView ID="fileGridview" UseAccessibleHeader="true" runat="server" CssClass="table table-hover table-striped" GridLines="None" AutoGenerateColumns="false" EmptyDataText="No Files Uploaded">
- <Columns>
- <asp:BoundField DataField="Text" HeaderText="File Name"/>
- <asp:TemplateField>
- <ItemTemplate>
- <asp:LinkButton ID="DownloadLink" runat="server" Text="Download" OnClick="DownloadData" CommandArgument='<%# Eval("Value") %>'><img src="Image/ic_download.png" /></asp:LinkButton>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField>
- <ItemTemplate>
- <asp:LinkButton ID="DeleteLink" runat="server" Text="Delete" OnClick="DeleteData" CommandArgument=' <%# Eval("value") %>'><img src="Image/ic_document.png" /></asp:LinkButton>
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- </asp:GridView>
- <script type="text/javascript">
- $(document).ready(function() {
- $('#fileGridview').DataTable();
- } );
- </script>
- </div>
- </form>
- </body>
- </html>







Join the conversation! Your thoughts help the community grow.