asp.net自动从项目中的特定文件夹中删除数据 [英] asp.net auto delete data from a specific folder in a project
本文介绍了asp.net自动从项目中的特定文件夹中删除数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我有一个网络项目,旁边有一个文件夹,我上传了一些文件然后放了。
我想在超过50 MB的时候删除该文件。
有没有slution那么请帮助我。
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.
推荐答案
你必须创建一个Web服务,定期检查文件夹的大小,如果它超过特定大小,则清空文件夹。
private void clearFolder(string FolderNameWithPath)
{
DirectoryInfo dir = new DirectoryInfo(FolderName);
foreach(文件信息fi在dir.GetFiles()中)
{
fi.Delete(); < br $>
}
foreach(目录信息在dir.GetDirectories()中)
{
clearFolder(di.FullName);
di.Delete();
}
}
或者你可以使用
System.IO.Directory.Delete(C:\ Temp,true);
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);
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.
}
这篇关于asp.net自动从项目中的特定文件夹中删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文