R
Ryan Moore
In an asp.net app, I'm trying to do some file upload / deleting for an image
gallery.
Deleting an image works great, except right after I have uploaded the file -
I cannot seem to get file access.
What do I need to do to solve this problem?
public bool DeleteImage(string fileName){
if (File.Exists(fileName))
{
try
{
if (this.WaitForExculsiveAccess(fileName))
{
System.IO.File.Delete(fileName);
return true;
}
else
{
return false;
}
}
catch (Exception e3)
{
return false;
}
}
else
{
return false;
}
}
private bool WaitForExculsiveAccess(string FullPath)
{
int ccount=0;
while (true)
{
if (ccount<5)
{
try
{
FileStream fs = new FileStream(FullPath, FileMode.Append, FileAccess.Write,
FileShare.None);
fs.Close();
return true;
}
catch
{
ccount++;
Thread.Sleep(1000);
}
}
else
{
return false;
}
}
}
gallery.
Deleting an image works great, except right after I have uploaded the file -
I cannot seem to get file access.
What do I need to do to solve this problem?
public bool DeleteImage(string fileName){
if (File.Exists(fileName))
{
try
{
if (this.WaitForExculsiveAccess(fileName))
{
System.IO.File.Delete(fileName);
return true;
}
else
{
return false;
}
}
catch (Exception e3)
{
return false;
}
}
else
{
return false;
}
}
private bool WaitForExculsiveAccess(string FullPath)
{
int ccount=0;
while (true)
{
if (ccount<5)
{
try
{
FileStream fs = new FileStream(FullPath, FileMode.Append, FileAccess.Write,
FileShare.None);
fs.Close();
return true;
}
catch
{
ccount++;
Thread.Sleep(1000);
}
}
else
{
return false;
}
}
}