Before Uploading the file am asking the user to specify whether to upload image, pdf, text and based on that if user select Text the folder with Text is created in the Project for the first time and if user once again select Text then the file will be added to that Folder which was previously created.
HTML:
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlFileExtension" runat="server">
<asp:ListItem Text="Image" />
<asp:ListItem Text="Pdf" />
<asp:ListItem Text="text" />
<asp:ListItem Text="Word" />
</asp:DropDownList>
<asp:FileUpload ID="fuTextFile" runat="server" />
<asp:Button ID="Button1" Text="Open" OnClick="SaveTextFile" runat="server" />
</div>
</form>
C#:
protected void SaveTextFile(object sender, EventArgs e)
{
if (this.fuTextFile.HasFile)
{
string folder = this.ddlFileExtension.SelectedItem.Text;
string sDirPath = Server.MapPath(folder);
DirectoryInfo ObjSearchDir = new DirectoryInfo(sDirPath);
if (!ObjSearchDir.Exists)
{
ObjSearchDir.Create();
}
this.fuTextFile.SaveAs(ObjSearchDir + "/" + fuTextFile.FileName);
}
}