I have a problem in Windows Azure. I’m storing temporary files in local storage. After a certain time i get a System.IO.IOException: There is not enough space on the disk.
So I have read some articles about it and microsoft themself recommends to catch the error and try to clear the files. So my question at this point is how is the best way to accomplish this?
At the moment I would try this but I don’t know if this is the best approach:
public static void ClearTempFolder(string localStorageName)
{
System.IO.DirectoryInfo downloadedMessageInfo = new DirectoryInfo(RoleEnvironment.GetLocalResource(localStorageName).RootPath);
foreach (FileInfo file in downloadedMessageInfo.GetFiles())
file.Delete();
foreach (DirectoryInfo dir in downloadedMessageInfo.GetDirectories())
dir.Delete(true);
}
Thanks for your help.
If you’re happy for all the files to go – then, yes, that should work fine. You may want to trap for exceptions that will be thrown if a file is still open.
However, it may be better to examine your code to see whether you can remove the temporary file immediately when you’ve finished with it.