In my project I am capturing image through webcam and displaying on image control. The image is captured on the model popup by opening the model popup. And is transferred to the parent page using the session.
Now I want to store that image in a date-wise directory. Suppose a directory with the current date name does not exist, it will first create a directory with the current date name and the image should be stored in the directory with the current date name.
I've tried the following but it doesn't work.
cmd.Parameters.Add("@U_IMAGE", SqlDbType.Binary).Value = bytes;
string image = vimagehidden.Value; //hidden control
var WebClient = new WebClient();
byte[] imgbytes = WebClient.DownloadData(image);
string MainDir = @"~/userimage/";
String SubDir = DateTime.Now.ToString("dd-MM-yyyy");
if (!Directory.Exists(Server.MapPath(MainDir + SubDir + "/")))
{
Directory.CreateDirectory(Server.MapPath(MainDir + SubDir + "/"));
}
string imgname = ("Image.jpg");
File.WriteAllBytes(Path.Combine(Server.MapPath(MainDir + SubDir), imgname), imgbytes);