Hi chetan,
Check this example. Now please take its reference and correct your code.
HTML
<asp:FileUpload ID="fuUpload" runat="server" />
<asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick="Upload" />
Code
C#
protected void Upload(object sender, EventArgs e)
{
if (fuUpload.HasFile)
{
string fileName = System.IO.Path.GetFileNameWithoutExtension(fuUpload.PostedFile.FileName);
string extension = System.IO.Path.GetExtension(fuUpload.PostedFile.FileName);
string fileLocation = Server.MapPath("~/Files/") + fileName + extension;
fuUpload.SaveAs(fileLocation);
}
}
VB.Net
Protected Sub Upload(ByVal sender As Object, ByVal e As EventArgs)
If fuUpload.HasFile Then
Dim fileName As String = System.IO.Path.GetFileNameWithoutExtension(fuUpload.PostedFile.FileName)
Dim extension As String = System.IO.Path.GetExtension(fuUpload.PostedFile.FileName)
Dim fileLocation As String = Server.MapPath("~/Files/") & fileName & extension
fuUpload.SaveAs(fileLocation)
End If
End Sub