In my C# application I'm creating tags for mp3 files. For this I use the TagLib library/extension.
One of the tags is the artwork. I can successfully add the artwork to the mp3's tag by using:
TagLib.File f = TagLib.File.Create(path);
IPicture[] pictures = new IPicture[1];
pictures[0] = new Picture(artwork);
f.Tag.Pictures = pictures;
path
is the full path to the mp3, artwork
is the full path to the artwork.
After assigning to the Pictures tag, I use:
f.Save();
f.Dispose();
Now, it is also in my interest to move the artwork file to another location on the computer.
For this I use:
File.Move(pathArtOrig, pathArtNew);
pathArtOrig
is the current full path of the artwork file, and pathArtNew
is the full path of where it's going to be moved to.
The problem is the fact that I get the following error:
IOException was unhandled. The process cannot access the file because it is being used by another process.
I have simply no idea to "release" the resource of the artwork file used (it could be a .jpg file). As you can see, I tried with Dispose() above, but that's not doing the trick.
Any help is appreciated.
Sorry, it seems I just found the error myself.
One place in my code, before tag creation, I was loading the file into a picturebox. It is stored in a Bitmap.
Now I Dispose() this Bitmap before the tag creation, and all is fine. File can now be moved.