how to create folder if missing in asp.net website
Literature
Problem: how to create folder if missing in website
Solution:
add key in web.config
<add key="UploadedFilePath" value="C:\menuitemphoto\"></add>
in your asp.net code write below
string fileuploaddingpath = ConfigurationManager.AppSettings["UploadedFilePath"];
try
{
if (!Directory.Exists(fileuploaddingpath))
{
DirectoryInfo di = Directory.CreateDirectory(fileuploaddingpath); // Try to create the directory. if there is no directory in application
}
}
catch (IOException ioex)
{
Console.WriteLine(ioex.Message);
}
HttpPostedFileBase selectedFile1 = Request.Files["txtImgItemPhoto"];
if (selectedFile1 != null && selectedFile1.ContentLength > 0)
{
if (selectedFile1 != null && selectedFile1.ContentLength > 0)
{
var updatedfilename = selectedFile1.FileName.Replace(" ", "-");
var fileName = "photo1_" + DateTime.Now.ToFileTimeUtc() + Path.GetFileName(updatedfilename);
var fileNamethmb = fileName;
// var aa = Path.Combine(fileuploaddingpath, fileName);
var imagePath = Path.Combine(fileuploaddingpath, fileName);
selectedFile1.SaveAs(imagePath);
dt.MenuItemPictureBox = imagePath;
}
}
File uploading, file upload
Share This with your friend by choosing any social account