Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 199995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:04:21+00:00 2026-05-11T17:04:21+00:00

What is the best way in .Net to make sure a path as capacity

  • 0

What is the best way in .Net to make sure a path as capacity to store a file. I need to makes sure I have room for the file before I download is becasue the source will not allow the file to be downloaded a second time. I have looked at System.IO.DriveInfo but this does not work for UNC paths.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:04:22+00:00Added an answer on May 11, 2026 at 5:04 pm

    Here’s a short function taken from this page that shows how you can get the free space of any drive (local or network/UNC) using WMI.

    private static ulong GetFreeDiskSpaceInBytes(string drive)
    {
        ManagementObject disk =
            new ManagementObject("win32_logicaldisk.deviceid=\"" + drive + ":\"");
        disk.Get();
        return (ulong)disk["FreeSpace"];
    }
    

    If you wnat a Win32 API solution, you can use the GetDiskFreeSpaceEx function, as suggested by this MSDN help page. It too seems to support both local and network drive names.

    Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
        Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, _
        lpFreeBytesAvailableToCaller As Currency, _
        lpTotalNumberOfBytes As Currency, _
        lpTotalNumberOfFreeBytes As Currency) As Long
    
    Private Sub Form_Click()
        Dim Status As Long
        Dim TotalBytes As Currency
        Dim FreeBytes As Currency
        Dim BytesAvailableToCaller As Currency
    
        Status = GetDiskFreeSpaceEx(Text1.Text, BytesAvailableToCaller, _
          TotalBytes, FreeBytes)
        If Status <> 0 Then
            MsgBox Format(TotalBytes * 10000, "#,##0"), , "Total Bytes"
            MsgBox Format(FreeBytes * 10000, "#,##0"), , "Free Bytes"
            MsgBox Format(BytesAvailableToCaller * 10000, "#,##0"), , _
              "Bytes Available To Caller"
        End If
    End Sub
    

    If you’re having trouble converting that to C#, let me know.

    I would have to recommend the WMI solution here, it being fully managed (aside from fewer lines), but either should do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: ASP.Net:Best way to run scheduled tasks I have to make a scheduled
What's the best way to have two websites (asp.net based) running on different domains
What's the best way (in .NET 4) to create an instance of a type
what is the best way to remote debugging .NET on server without install VS?
In .NET what is the best way to find the length of an integer
What is the best way to read and write .INI files in .NET? It
What is the best way to unit test heavily database dependant .NET middleware? E.g.
What's the best way to handle an expired password in an ASP.NET MVC application?
What is the best way to rotate a image in asp.net I did use
What is the best way to achieve application authorization and entitlement in .Net. Earlier

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.