Reputation: 128
Please I need to assist me to solve a problem with save live web camera image into a wwwroot folder with Id of a staff. the code I'm used saving image from web camera with default filename but need to change to save with Id. below is the sample code.
var fileName = file.FileName;
var fileNameToStore = string.Concat(Convert.ToString(Guid.NewGuid()), Path.GetExtension(fileName));
Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\Photos", fileName);
var filepath = Path.Combine(_environment.WebRootPath, "Photos") + $@"\{fileNameToStore}";
// Save image file in local folder
if (!string.IsNullOrEmpty(filepath))
{
using (FileStream fileStream =
System.IO.File.Create(filepath))
{
file.CopyTo(fileStream);
fileStream.Flush();
}
}
saved with: 03f59a92-65e0-4deb-80a4-b56e91d89d88.png but I need to save like this: 10001.png
Upvotes: 1
Views: 372
Reputation: 502
You need to replace:
var fileNameToStore = string.Concat(Convert.ToString(Guid.NewGuid()), Path.GetExtension(fileName));
with:
var fileNameToStore = string.Concat("10001", Path.GetExtension(fileName));
If you want to actually get the right ID at runtime you need some kind of data source for that. User Input? Windows Login? What data is available to you?
Upvotes: 1