Hey irshad1231,
Please refer below sample.
HTML
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<hr />
<asp:TextBox runat="server" ID="txtPath" />
<asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick="UploadFile" />
<br />
<asp:Label ID="lblMessage" ForeColor="Green" runat="server" />
</div>
Namespaces
C#
using System.IO;
VB.Net
Imports System.IO
Code
C#
protected void UploadFile(object sender, EventArgs e)
{
string folderPath = Server.MapPath("~/" + txtPath.Text);
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
FileUpload1.SaveAs(folderPath + "/" + Path.GetFileName(FileUpload1.FileName));
lblMessage.Text = Path.GetFileName(FileUpload1.FileName) + " has been uploaded." + txtPath.Text;
}
VB.Net
Protected Sub UploadFile(ByVal sender As Object, ByVal e As EventArgs)
Dim folderPath As String = Server.MapPath("~/" & txtPath.Text)
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
FileUpload1.SaveAs(folderPath & "/" & Path.GetFileName(FileUpload1.FileName))
lblMessage.Text = Path.GetFileName(FileUpload1.FileName) & " has been uploaded." & txtPath.Text
End Sub
Screenshot