Hello Sir,
Below is the code which i am using to create a folder at runtime and upload the files to the same, its working correctly on localhost, but after hosting im getting error
Error : Access to path is denied
Please help.
if (FileUpload1.HasFile)
{
try
{
string folder_name = DropDownList1.SelectedItem.Text;
string folderPath = Server.MapPath("~/" + DropDownList1.SelectedItem.Text + "/");
//Check whether Directory (Folder) exists.
if (!Directory.Exists(folderPath))
{
//If Directory (Folder) does not exists. Create it.
Directory.CreateDirectory(folderPath);
}
//Save the File to the Directory (Folder).
// FileUpload1.SaveAs(folderPath + Path.GetFileName(FileUpload1.FileName));
// Get the HttpFileCollection
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
hpf.SaveAs(folderPath + "\\" +
Path.GetFileName(hpf.FileName));
}
}
}
catch (Exception ex)
{
// Handle your exception here
throw ex;
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "SweetAlert", "swal('Success!', 'Files uploaded successfully successfully.!', 'success');", true);
DropDownList1.ClearSelection();
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "SweetAlert", "swal('Warning!', 'Please select files to be uploaded.!', 'warning');", true);
}
Thanks