I am planning to have code to detect the file size of a db1 file I am using inside App_Data and if its size exceed
say 5G then my next add record to db will use connectionstring2 to add to db2 instead.
So in the first place what is the code to get file size of db1 ?
Thanks
Thanks. I will try to credit the ones who helped but most important is we really do sincerely thanks to all who have helped.
You can use the
FileInfo.Length property to get the size of file
Sample Code
//Change the name of file accordingly
string path = Server.MapPath("~/App_Data/db1.mdf");
System.IO.FileInfo file = new System.IO.FileInfo(path);
//Check if file exists or not
if (file.Exists)
{
//FileSize in bytes
long filesize = file.Length;
//Converting Bytes to GB
long Gbsize = filesize / (1024 * 1024 * 1024);
}
Participant
753 Points
2406 Posts
How to detect file size of a file inside App_Data
Oct 11, 2017 03:19 AM|hkbeer|LINK
I am planning to have code to detect the file size of a db1 file I am using inside App_Data and if its size exceed
say 5G then my next add record to db will use connectionstring2 to add to db2 instead.
So in the first place what is the code to get file size of db1 ?
Thanks
www.developerfusion.com/tools/convert/csharp-to-vb/
All-Star
50831 Points
9895 Posts
Re: How to detect file size of a file inside App_Data
Oct 11, 2017 05:06 AM|A2H|LINK
You can use the FileInfo.Length property to get the size of file
Sample Code
Aje
My Blog | Dotnet Funda