Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hello

I have a web project and in side that there is a folder where i am upload some file and put that.

I want to delete that file when it exceed to 50 MB.


Is there any slution then please help me.
Posted
Comments
ZurdoDev 7-Mar-13 7:01am    
Yes, when you are uploading it check the size and then delete if it is too big.

you must create a web service that will check periodically the size of folder and if it will exceed then specific size then empty the folder.

private void clearFolder(string FolderNameWithPath)
{
DirectoryInfo dir = new DirectoryInfo(FolderName);

foreach(FileInfo fi in dir.GetFiles())
{
fi.Delete();
}

foreach (DirectoryInfo di in dir.GetDirectories())
{
clearFolder(di.FullName);
di.Delete();
}
}

Or you can use

System.IO.Directory.Delete("C:\Temp", true);
 
Share this answer
 
C#
DirectoryInfo dirInfo = new DirectoryInfo(@"D:\Songs");
            long total = 0;
            long sizePerMb = 1024;
            foreach (FileInfo file in dirInfo.GetFiles())
            {
                total += Convert.ToInt32(file.Length);
            }
            long size = total / sizePerMb;
            size = size / sizePerMb;
            if (size >= 50)
            { 
//write here logic to delete file after deleting again check size if it's OK then break loop else keep continue.
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900