Reputation: 21
I would like to tag some existing mp3 with taglib#. I have the following error message: "The process cannot access the file because it is being used by another process." I don't know what kind of process it can be. I can access any mp3 files on any of my hard drives, I also can use the properties of the file, but I cannot save changes.
This is the code.
OpenFileDialog f = new OpenFileDialog();
if ((bool)f.ShowDialog())
{
try
{
if ( f.OpenFile() != null)
{
TagLib.File file = TagLib.File.Create(f.FileName);
file.Tag.Album = "Album1";
file.Save();
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
else
{
MessageBox.Show("Problem occured, try again later");
}
Could you help me? Thanks
Upvotes: 1
Views: 1320
Reputation: 887275
f.OpenFile()
creates a FileStream
around the file.
Since you never close this stream, the file remains open.
Don't do that.
Upvotes: 2