private void MoveFile(string destination, string imagePath)
{
try
{
string source = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["TempImagePath"]);
string[] resizedImage = imagePath.Split('.');
//string compressedImagePath = resizedImage[0] + "_compress." + resizedImage[1];
string thumbnail150Name = resizedImage[0] + "_thumbnail." + resizedImage[1];
string mediumPhoto300Name = resizedImage[0] + "_mediumPhoto." + resizedImage[1];
string largePhotoName = resizedImage[0] + "_largePhoto." + resizedImage[1];
//Move thumbnail
if (System.IO.File.Exists(source + "\\" + thumbnail150Name))
{
if (!System.IO.Directory.Exists(destination))
{
DirectoryInfo di = System.IO.Directory.CreateDirectory(destination);
}
System.IO.File.Move(source + "\\" + thumbnail150Name, destination + "\\" + thumbnail150Name);
}
//Move medium sized photo
if (System.IO.File.Exists(source + "\\" + mediumPhoto300Name))
{
if (!System.IO.Directory.Exists(destination))
{
DirectoryInfo di = System.IO.Directory.CreateDirectory(destination);
}
System.IO.File.Move(source + "\\" + mediumPhoto300Name, destination + "\\" + mediumPhoto300Name);
}
//Move large photo
if (System.IO.File.Exists(source + "\\" + largePhotoName))
{
if (!System.IO.Directory.Exists(destination))
{
DirectoryInfo di = System.IO.Directory.CreateDirectory(destination);
}
System.IO.File.Move(source + "\\" + largePhotoName, destination + "\\" + largePhotoName);
}
//Move original
if (System.IO.File.Exists(source + "\\" + imagePath))
{
if (!System.IO.Directory.Exists(destination))
{
DirectoryInfo di = System.IO.Directory.CreateDirectory(destination);
}
System.IO.File.Move(source + "\\" + imagePath, destination + "\\" + imagePath);
}
}
catch (Exception ex)
{
BgLogger.FileLogger.LogError("In private method : MoveFile(string, string), On server : " + Dns.GetHostName() + " At : " + DateTime.Now, ex).Wait();
}
}
Ich verwende diesen Code beim Verschieben einer Bilddatei. Aber ich erhalte die folgende AusnahmeIOException beim Verschieben einer Bilddatei
System.IO.IOException: Der Prozess kann nicht auf die Datei zugreifen kann, weil es wird von einem anderen Prozess verwendet wird.
bei System.IO .__ Error.WinIOError (Int32 errorcode, String maybeFullPath) bei System.IO.File.InternalMove (String source, String Destfilename, Boolean checkHost) bei BgPortal.Controllers.DriverController.MoveFile (String Ziel, String imagePath) https://u3307993.ct.sendgrid.net/wf/open?upn=mzyvlCvUM5odb-2FP3IS9fxavC9Nq-2BVU-2BlgxLxmreq6Qi5SziY4JAfC5R720TrBfTXj7GdvSOgEG2Qeq-2BGKm-2FwWmPOrbAem6UFnvcBKca-2FzIM3XkXg0dHdke9rhjcAKDqtd0MJQCnmyIN-2Fi-2FXbgygtnXFNxuEuwts4hybPsnVR72PsfW4L6YZ32pnlEuwGMF-2Fcg0S8f8Y7UOBHwDMzh1BgJnhqO9i5dgS9LRZytY4n6TNCt37JAtdi5EOj8OxBqhan
Diese Ausnahme tritt sehr zufällig.
Kann mir jemand dabei helfen?