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
Alok UniyalPosted Jan 25, 2012, 6:58 AM
Sunny SinghPosted Jan 25, 2012, 6:44 AM
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
Mukesh KumarPosted Jan 25, 2012, 6:42 AM
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);
}
}
Alok UniyalPosted Jan 25, 2012, 6:07 AM
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);
}
Hemant KumarPosted Jan 25, 2012, 5:47 AM
if(File.Exists("file_path"))
{
//Do Something
}
else
{
// Do Some thing
}