I'm trying to create a basic image conversion tool, which converts images to a .jpeg format, and then further down the line to a Base64 value for some SQL inserts.
I'm currently getting the error in the title when running the code.
The below is a little messy, as I've been trying to fix this for a while and this section has gone through many iterations. I've looked at similar queries, but none have seemed to fit the scenario or fixed the issue.
My experience in C# is limited, so apologies if I have follow-up questions regarding the implementation of a fix if one comes about.
private void imageLocationBtn_Click(object sender, EventArgs e)
{
byte i = 0;
//Open folder browser
FolderBrowserDialog openFileDialog1 = new FolderBrowserDialog();
//Take image names and put them into the list box
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string strFilename = openFileDialog1.SelectedPath;
imageLocationTxtBx.Text = strFilename;
//Display File Names found
string root = strFilename;
string[] fileEntries = Directory.GetFiles(root);
foreach (string fileNameRoot in fileEntries)
{
string fileName = fileNameRoot.Substring((fileNameRoot.LastIndexOf('\\') + 2), ((fileNameRoot.LastIndexOf('.')) - (fileNameRoot.LastIndexOf('\\') + 2)));
Bitmap bmp1 = new Bitmap(Image.FromFile(fileNameRoot));
File.Delete(fileNameRoot);
bmp1.Save("C:\\Users\\HobbitForHire\\Pictures\\Conversion Images\\" + fileName + ".Jpeg", ImageFormat.Jpeg);
}