2012-03-16 87 views
0

我想用taglib#標記一些現有的mp3。 我有以下錯誤信息: 「進程無法訪問該文件,因爲它正在被另一個進程使用。」 我不知道它可以是什麼樣的過程。我可以訪問我的任何硬盤驅動器上的任何mp3文件,我也可以使用該文件的屬性,但我無法保存更改。taglib#無法保存更改

這是代碼。

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"); 
} 

你能幫幫我嗎? 謝謝

+0

如果這真的是你的錯誤,你的問題更多的是找出什麼是MP3文件。是否http://stackoverflow.com/questions/317071/how-do-i-find-out-which-process-is-locking-a-file-using-net和http://stackoverflow.com/questions/177146/how-do-i-get-the-list-of-open-file-by-process-in-c help?除非,你不打開寫訪問流?奇怪的是,未使用的MP3正在使用。 – Jason 2012-03-16 23:11:05

+1

'f.OpenFile()'永遠不會返回'null'。 – SLaks 2012-03-16 23:13:35

+0

爲什麼你認爲點擊取消意味着問題出現? – SLaks 2012-03-16 23:14:00

回答

2

f.OpenFile()在文件周圍創建一個FileStream
由於您從不關閉此流,因此文件保持打開狀態。

不要這樣做。