Size. aspx File
Code :
<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Size. aspx. CS " Inherits = " Size " %>
<! Doctype HTML public " -// W3C // dtd xhtml 1.0 transitional // en " " Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< HTML xmlns = " Http://www.w3.org/1999/xhtml " >
< Head runat = " Server " >
< Title > Calculate the folder size value </ Title >
</ Head >
< Body >
< Form ID = " Form1 " Runat = " Server " >
< Div >
< ASP: Label ID = " Label1 " Runat = " Server " Text = " Label " > </ ASP: Label >
</ Div >
</ Form >
</ Body >
</ Html >
Size. aspx. CS background code:
Using System;
Using System. Data;
Using System. configuration;
Using System. collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;
Using System. IO;
Using System. text;
Public Partial Class Size: system. Web. UI. Page
{
Public Int Str = 0 ;
Protected Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback)
{
StringDpath=Server. mappath (".");
Label1.text=Getsize (dpath). tostring ();
}
}
Private Int Getsize ( String Dirp)
{
Directoryinfo mydir = New Directoryinfo (dirp );
Foreach (Filesysteminfo FSI In Mydir. getfilesysteminfos ())
{
If (FSI Is Fileinfo)
{
Fileinfo fi=(Fileinfo) FSI;
Str+ =Int. Parse (Fi. length. tostring ());
}
Else
{
Directoryinfo di=(Directoryinfo) FSI;
StringNew_dir=Di. fullname;
Getsize (new_dir );
}
}
Return STR;
}
}