fn = Guid.NewGuid().ToString() + fuUploadFile.FileName.Substring(fuUploadFile.FileName.LastIndexOf("."));
string filepath = Server.MapPath("~/Temp" + "\\" + fn);fuFile.PostedFile.SaveAs(filepath);
I want it should check first whether folder (Temp) exists or not , if it does not exist it should create & if successfully created then it should save file. Secondly i want that folder name should be given in Web.Config from there it should pick name of folder & that it should check & create.
Thanx

Hemant KumarRank #1,202 · 1.5K reputationPosted Jan 25, 2012, 12:47 AM EST
if(File.Exists("file_path"))
{
//Do Something
}
else
{
// Do Some thing
}
Alok UniyalRank #8,369 · 223 reputationPosted Jan 25, 2012, 1:07 AM EST
you may this will help you-
string filename = Path.GetFileName(FileUploadControl.FileName);
if(Directory.Exists( "~/ Temp/" ))
{
FileUploadControl.SaveAs(Server.MapPath("~/Temp/") + filename);
}
else
{
DirectoryInfo di = Directory.CreateDirectory( "~/ Temp/" );
FileUploadControl.SaveAs(Server.MapPath("~/ Temp/") + filename);
}
Mukesh KumarRank #615 · 3.9K reputationPosted Jan 25, 2012, 1:42 AM EST
Try this...
string Apath = Server.MapPath("~/") + "UploadedFiles";
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (!string.IsNullOrEmpty(hpf.FileName))
{
string FileName = Path.GetFileName(hpf.FileName);
if (!Directory.Exists(Apath))
Directory.CreateDirectory(Apath);
hpf.SaveAs(Apath + "\\" + FileName);
}
}
Sunny Singh8 reputationPosted Jan 25, 2012, 1:44 AM EST
I have writen this
if(Directory.Exists("~/Temp/"))
{
DirectoryInfo di = Directory.CreateDirectory("~/Temp/");
string vpath = Server.MapPath("~/Temp" + "\\" + fn);
fuFile.PostedFile.SaveAs(vpath);
}
Even if folder does not exists even then it is going in this condition . If it is going in this then it is not creating folder also.
Thanx
Alok UniyalRank #8,369 · 223 reputationPosted Jan 25, 2012, 1:58 AM EST