Ok so now we need to be able to save all the existing images from a folder... So we came up with a simple code to help us on this hard and time consuming task... and it goes a little something like this :)
private void ImportImageToDatabase()
{
//Get a path from the app.config app file
string path = ConfigurationManager.AppSettings.Get("ImagesPath");
foreach (var folder in Directory.GetDirectories(path))
{
//This variable will be needed so it's easier to get the folder name instead of having to do string operations
DirectoryInfo d = new DirectoryInfo(folder);
foreach (var file in Directory.GetFiles(folder))
{
//This variable will be needed so it's easier to get the file name instead of having to do string operations
FileInfo f = new FileInfo(file);
//Now we can call the method we previously created to get the image bytes and save them
Byte[] image = GetImageBytes(file);
//Save image to the database and we can get the name of the file by using f.Name
}
}
}
Nenhum comentário:
Postar um comentário