Playback starts YouTube’s embedded player (privacy-enhanced mode).
How to upload and download files using asp net and c# Part 139
ChannelkudvenkatDescription from the creator
Text version of the video
csharp-video-tutorials.blogspot.com/2013/08/how…
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?s…
Slides
csharp-video-tutorials.blogspot.com/2013/08/par…
All ASP .NET Text Articles
csharp-video-tutorials.blogspot.com/p/free-aspn…
All ASP .NET Slides
csharp-video-tutorials.blogspot.com/p/aspnet-sl…
ASP.NET Playlist
youtube.com/playlist?list=PL4cyC4G0M1RQcB4IYS_z…
All Dot Net and SQL Server Tutorials in English
youtube.com/user/kudvenkat/playlists?view=1&…
All Dot Net and SQL Server Tutorials in Arabic
youtube.com/c/KudvenkatArabic/playlists
In this video, we will discuss
1. Uploading files
2. Displaying the list of files that are already uploaded
3. Downloading files
When the files are uploaded, they should be uploaded to a folder on the web server. In our case, we will be uploading to "Data" folder.
WebForm1.aspx code:
[div style="font-family:Arial"]
[asp:FileUpload ID="FileUpload1" runat="server" /]
[asp:Button ID="Button1" runat="server" Text="Upload"
OnClick="Button1_Click" /]
[br /]
[br /]
[asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
OnRowCommand="GridView1_RowCommand" BackColor="White"
BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4"]
[Columns]
[asp:TemplateField HeaderText="File" ShowHeader="False"]
[ItemTemplate]
[asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False"
CommandArgument='[%# Eval("File") %]'
CommandName="Download" Text='[%# Eval("File") %]']
[/asp:LinkButton]
[/ItemTemplate]
[/asp:TemplateField]
[asp:BoundField DataField="Size" HeaderText="Size in Bytes" /]
[asp:BoundField DataField="Type" HeaderText="File Type" /]
[/Columns]
[FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /]
[HeaderStyle BackColor="#990000" Font-Bold="True"
ForeColor="#FFFFCC" /]
[PagerStyle BackColor="#FFFFCC" ForeColor="#330099"
HorizontalAlign="Center" /]
[RowStyle BackColor="White" ForeColor="#330099" /]
[SelectedRowStyle BackColor="#FFCC66" Font-Bold="True"
ForeColor="#663399" /]
[SortedAscendingCellStyle BackColor="#FEFCEB" /]
[SortedAscendingHeaderStyle BackColor="#AF0101" /]
[SortedDescendingCellStyle BackColor="#F6F0C0" /]
[SortedDescendingHeaderStyle BackColor="#7E0000" /]
[/asp:GridView]
[/div]
WebForm1.aspx.cs code:
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileName = FileUpload1.FileName;
FileUpload1.PostedFile
.SaveAs(Server.MapPath("~/Data/") + fileName);
}
DataTable dt = new DataTable();
dt.Columns.Add("File");
dt.Columns.Add("Size");
dt.Columns.Add("Type");
foreach (string strfile in Directory.GetFiles(Server.MapPath("~/Data")))
{
FileInfo fi = new FileInfo(strfile);
dt.Rows.Add(fi.Name, fi.Length.ToString(),
GetFileTypeByExtension(fi.Extension));
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
private string GetFileTypeByExtension(string fileExtension)
{
switch (fileExtension.ToLower())
{
case ".docx":
case ".doc":
return "Microsoft Word Document";
case ".xlsx":
case ".xls":
return "Microsoft Excel Document";
case ".txt":
return "Text Document";
case ".jpg":
case ".png":
return "Image";
default:
return "Unknown";
}
}
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "Download")
{
Response.Clear();
Response.ContentType = "application/octect-stream";
Response.AppendHeader("content-disposition", "filename="
+ e.CommandArgument);
Response.TransmitFile(Server.MapPath("~/Data/")
+ e.CommandArgument);
Response.End();
}
}
Please make sure to include the following using declarations in the code behind file.
using System.IO;
using System.Data;
Make sure to replace [ with LESSTHAN and ] with GREATERTHAN symbol.
csharp-video-tutorials.blogspot.com/2013/08/how…
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?s…
Slides
csharp-video-tutorials.blogspot.com/2013/08/par…
All ASP .NET Text Articles
csharp-video-tutorials.blogspot.com/p/free-aspn…
All ASP .NET Slides
csharp-video-tutorials.blogspot.com/p/aspnet-sl…
ASP.NET Playlist
youtube.com/playlist?list=PL4cyC4G0M1RQcB4IYS_z…
All Dot Net and SQL Server Tutorials in English
youtube.com/user/kudvenkat/playlists?view=1&…
All Dot Net and SQL Server Tutorials in Arabic
youtube.com/c/KudvenkatArabic/playlists
In this video, we will discuss
1. Uploading files
2. Displaying the list of files that are already uploaded
3. Downloading files
When the files are uploaded, they should be uploaded to a folder on the web server. In our case, we will be uploading to "Data" folder.
WebForm1.aspx code:
[div style="font-family:Arial"]
[asp:FileUpload ID="FileUpload1" runat="server" /]
[asp:Button ID="Button1" runat="server" Text="Upload"
OnClick="Button1_Click" /]
[br /]
[br /]
[asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
OnRowCommand="GridView1_RowCommand" BackColor="White"
BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4"]
[Columns]
[asp:TemplateField HeaderText="File" ShowHeader="False"]
[ItemTemplate]
[asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False"
CommandArgument='[%# Eval("File") %]'
CommandName="Download" Text='[%# Eval("File") %]']
[/asp:LinkButton]
[/ItemTemplate]
[/asp:TemplateField]
[asp:BoundField DataField="Size" HeaderText="Size in Bytes" /]
[asp:BoundField DataField="Type" HeaderText="File Type" /]
[/Columns]
[FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /]
[HeaderStyle BackColor="#990000" Font-Bold="True"
ForeColor="#FFFFCC" /]
[PagerStyle BackColor="#FFFFCC" ForeColor="#330099"
HorizontalAlign="Center" /]
[RowStyle BackColor="White" ForeColor="#330099" /]
[SelectedRowStyle BackColor="#FFCC66" Font-Bold="True"
ForeColor="#663399" /]
[SortedAscendingCellStyle BackColor="#FEFCEB" /]
[SortedAscendingHeaderStyle BackColor="#AF0101" /]
[SortedDescendingCellStyle BackColor="#F6F0C0" /]
[SortedDescendingHeaderStyle BackColor="#7E0000" /]
[/asp:GridView]
[/div]
WebForm1.aspx.cs code:
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileName = FileUpload1.FileName;
FileUpload1.PostedFile
.SaveAs(Server.MapPath("~/Data/") + fileName);
}
DataTable dt = new DataTable();
dt.Columns.Add("File");
dt.Columns.Add("Size");
dt.Columns.Add("Type");
foreach (string strfile in Directory.GetFiles(Server.MapPath("~/Data")))
{
FileInfo fi = new FileInfo(strfile);
dt.Rows.Add(fi.Name, fi.Length.ToString(),
GetFileTypeByExtension(fi.Extension));
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
private string GetFileTypeByExtension(string fileExtension)
{
switch (fileExtension.ToLower())
{
case ".docx":
case ".doc":
return "Microsoft Word Document";
case ".xlsx":
case ".xls":
return "Microsoft Excel Document";
case ".txt":
return "Text Document";
case ".jpg":
case ".png":
return "Image";
default:
return "Unknown";
}
}
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "Download")
{
Response.Clear();
Response.ContentType = "application/octect-stream";
Response.AppendHeader("content-disposition", "filename="
+ e.CommandArgument);
Response.TransmitFile(Server.MapPath("~/Data/")
+ e.CommandArgument);
Response.End();
}
}
Please make sure to include the following using declarations in the code behind file.
using System.IO;
using System.Data;
Make sure to replace [ with LESSTHAN and ] with GREATERTHAN symbol.
About this tutorial
kudvenkat published this 24:16 video tutorial on November 13, 2013. It has been watched 299,180 times on YouTube.
Tags
Share
This tutorial in other languages
- FRComment télécharger et télécharger des fichiers en utilisant net et c # asp Partie 139
- ESCómo cargar y descargar archivos utilizando ASP NET y C # Parte 139
- PTComo fazer upload e download de arquivos usando ASP NET e C # Parte 139
- ITCome caricare e scaricare file usando asp net e C # parte 139
- DEWie zum Hochladen und Herunterladen von Dateien asp net mit und c # Teil 139
- NLHoe te uploaden en downloaden van bestanden met behulp van asp net en C # Part 139
- RUКак загрузить и загрузить файлы с помощью ASP NET и C # Часть 139
- PLJak przesyłać i pobierać pliki przy użyciu ASP NET oraz C # Part 139
- JAパート139 ASPネットとC#を使用してファイルをアップロードおよびダウンロードする方法
- ARكيفية تحميل وتنزيل الملفات باستخدام شبكة آسيا والمحيط الهادئ وج # الجزء 139
- HIकैसे अपलोड और एएसपी शुद्ध और सी # का उपयोग कर भाग 139 डाउनलोड फ़ाइलों को
- IDBagaimana meng-upload dan download file menggunakan asp net dan c # Part 139