我有一個奇怪的問題。 我將上傳的文件保存到數據庫,然後嘗試從上傳文件夾中刪除上傳的文件 。File.Delete()不能在運行模式下工作,但只能在調試模式下工作
這在調試模式下工作正常,但在運行模式下,文件保持未刪除狀態。
任何人都遇到過這個問題?
這是.NET低於4
代碼片段:
private string SaveFiles(string rootFolder)
{
var uploadedPhotos = GetAllFilesUploaded();
foreach (var file in uploadedFiles)
{
string path= Path.Combine(rootFolder, "userfile", file.FileName);
FileService.SaveUploadedFile(fileName, GetBytesFromLocalFile(path));
File.Delete(path); <-- this only works in debug mode!!
}
}
public static byte[] GetBytesFromLocalFile(string filePath)
{
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, (int)fs.Length);
return bytes;
}
}
我遇到同樣的問題。你有沒有解決這個問題? – Jelling 2014-03-20 22:26:10