日期:2014-05-18  浏览次数:20864 次

C#中调用File.Delete(filePath)问题
在C#中,如何处理删除正在播放的媒体文件引发的异常?

现有
C# code

string filePath = "C:\\1.avi";


并且1.avi出于播放状态,在测试代码中写入:

C# code

try {
File.Delete(filePath);
}catch (IOExeption ioe) {
Console.WriteLine(ioe.Message);
}



试验证明,根本没有捕获到该异常。请教要捕获并处理该异常的方法,谢谢。

------解决方案--------------------
catch this:
public class UnauthorizedAccessException : System.SystemException
Member of System

Summary:
The exception that is thrown when the operating system denies access because of an I/O error or a specific type of security error.

------解决方案--------------------
System.UnauthorizedAccessException: 对路径“E:\新建文件夹\johnny.mp3”的访问被拒
绝。
在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.File.Delete(String path)
在 ConsoleApplication1.Program.Main(String[] args) 位置 C:\Documents and Sett
ings\S0807002\Local Settings\Application Data\Temporary Projects\ConsoleApplicat
ion1\Program.cs:行号 15