Hi samsmuthu,
Please refer below sample.
HTML
<table>
<tr>
<td>Name:</td>
<td><asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>File:</td>
<td><asp:FileUpload ID="fuFile" runat="server" /></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload" /></td>
</tr>
</table>
Namespaces
C#
using System.IO;
VB.Net
Imports System.IO
Code
C#
protected void Upload(object sender, EventArgs e)
{
string fileName = Path.GetFileName(fuFile.PostedFile.FileName).Replace(" ", "-");
string folderPath = txtName.Text.Replace(" ", "-");
if (!Directory.Exists(Server.MapPath("~/" + folderPath)))
{
Directory.CreateDirectory(Server.MapPath("~/" + folderPath));
}
fuFile.SaveAs(Server.MapPath("~/" + Path.Combine(folderPath, fileName)));
}
VB.Net
Protected Sub Upload(ByVal sender As Object, ByVal e As EventArgs)
Dim fileName As String = Path.GetFileName(fuFile.PostedFile.FileName).Replace(" ", "-")
Dim folderPath As String = txtName.Text.Replace(" ", "-")
If Not Directory.Exists(Server.MapPath("~/" & folderPath)) Then
Directory.CreateDirectory(Server.MapPath("~/" & folderPath))
End If
fuFile.SaveAs(Server.MapPath("~/" & Path.Combine(folderPath, fileName)))
End Sub