Last post Oct 11, 2017 05:06 AM by a2h
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 ?
Oct 11, 2017 05:06 AM|a2h|LINK
what is the code to get file size of db1 ?
You can use the
FileInfo.Length property to get the size of file
//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
//FileSize in bytes
long filesize = file.Length;
//Converting Bytes to GB
long Gbsize = filesize / (1024 * 1024 * 1024);