Get free disk space from Server.EnumAvailableMedia Method . RRS feed

  • Question

  • Does anyone know how to convert lowfree and highfree to megabytes?



    Friday, August 1, 2008 6:40 PM

All replies




    I suppose that the Sql Server team who has developped the method EnumAvailableMedia() has foreseen the possiblity of very,very large media, but i don't understand why they have not used Int64 which may contain upto 9 * ( 10 power 17 ).


    In VC#, you should have a code like :


    Code Snippet

    Int64 lowfree64 = Convert.ToInt64(lowfree);

    Int64 highfree64 = Convert.ToInt64(highfree * Math.Pow(2,32));

    Int64 tempres64 = (highfree64 + lowfree64) / (1024*1024);




    In tempres64, you should have your result in MB.

    But , be careful, with all the conversions, i think that an error of 2 MB is possible ...)


    A quicker solution is possible, if you post on VB/VC#/.Net Framework forums, maybe someone woumd be able to provide you a quicker solution.


    As i prefer VC#, i have posted in VC#.

    If you prefer VB, i may post this code in VB


    Have a nice day

    Saturday, August 9, 2008 3:08 PM
  • Hi,

    You can get Free Space (in bytes )available on a disk by using following logic

    Free Space= 
    4294967296.0 * highfree + (lowfree >= 0 ?  (0.0 + lowfree) : (4294967296.0 + lowfree) )

    [4294967296.0 =   2^32 ]

    In case of any doubt please revert.



    Please remember to click 'Mark as Answer' on the post that helped you. Unmark if it provides no help
    Tuesday, September 23, 2008 9:23 AM