Hi anirudhp,
Refer below sample code.
HTML
<asp:FileUpload ID="fuMultiple" runat="server" multiple="multiple" />
<br />
<asp:Button Text="Upload" runat="server" OnClick="Upload" />
<asp:Button Text="Save" runat="server" OnClick="Save" />
<br />
<asp:ListView runat="server" ID="lstview1">
<ItemTemplate>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:Label ID="Label1" Text='<%#Eval("Text") %>' runat="server" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:ListView>
Namespaces
C#
using System.IO;
VB.Net
Imports System.IO
Code
C#
protected void Upload(object sender, EventArgs e)
{
List<HttpPostedFile> files = new List<HttpPostedFile>();
for (int i = 0; i < Request.Files.Count; i++)
{
files.Add(Request.Files[i]);
}
lstview1.DataSource = (from f in files
select new
{
Text = f.FileName
}).ToList();
lstview1.DataBind();
Session["Files"] = files;
}
protected void Save(object sender, EventArgs e)
{
List<HttpPostedFile> files = Session["Files"] as List<HttpPostedFile>;
for (int i = 0; i < files.Count; i++)
{
files[i].SaveAs(Server.MapPath("~/uploads/") + files[i].FileName);
}
}
VB.Net
Protected Sub Upload(ByVal sender As Object, ByVal e As EventArgs)
Dim files As List(Of HttpPostedFile) = New List(Of HttpPostedFile)()
For i As Integer = 0 To Request.Files.Count - 1
files.Add(Request.Files(i))
Next
lstview1.DataSource = (From f In files Select New With {Key .Text = f.FileName}).ToList()
lstview1.DataBind()
Session("Files") = files
End Sub
Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs)
Dim files As List(Of HttpPostedFile) = TryCast(Session("Files"), List(Of HttpPostedFile))
For i As Integer = 0 To files.Count - 1
files(i).SaveAs(Server.MapPath("~/uploads/") + files(i).FileName)
Next
End Sub