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

  • Home
  • SEARCH
  • 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 6936641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:15:36+00:00 2026-05-27T12:15:36+00:00

Possible Duplicate: How to test if a file is fully copied in .NET As

  • 0

Possible Duplicate:
How to test if a file is fully copied in .NET

As of almost 2012, is there still no better way to check if a file is fully copied as to open it within a try~catch block?

I know it’s been asked before and I’ve checked the automatic related questions Stack Overflow offers, but they are over two years old, so perhaps a better solution exists today?

This is a similar question of 2009:
How to test if a file is fully copied in .NET

EDIT: I changed the question’s title since it raised “requestioning” issues.

  • 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-27T12:15:37+00:00Added an answer on May 27, 2026 at 12:15 pm

    No, there still isn’t a way to do that without using try ... catch, and if I were you I wouldn’t hold my breath waiting for one.

    What you’re really asking for is a group of functions that can tell you whether or not an attempt to open a file in a particular mode will succeed. Something like a File.CanOpenForExclusiveRead() or something similar. There are no such methods in .NET, and they don’t exist in the Windows API. And for good reason.

    Let’s say that such a function existed. That is, you could write:

    if (File.CanOpenForExclusiveRead(filename))
    {
        f = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None);
    }
    

    Sounds like a good idea, right? Except you’d still need to put a try ... catch around the FileStream constructor because some other thread (perhaps in another process) might open the file for exclusive read between the time your code checked and the time your code called the constructor. Or something else could go wrong: the file could be deleted, the disk could go offline, etc.

    To be sure, that fictional File.CanOpenForExclusiveRead method would be useful in some cases. Those cases, though, are few and far between, and as I showed above they wouldn’t do you a whole lot of good anyway, since you’d still have to handle possible exceptions anyway.

    If you want a method that does that, write your own that uses try ... catch and returns false if an exception is thrown. At least then you hide the details of the implementation. But don’t wait for a better solution. It’s highly unlikely that one is forthcoming.

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

Sidebar

Related Questions

Possible Duplicate: What's a quick way to test to see a file exists? I
Possible Duplicate: .NET file system wrapper library I would like to write a test
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: SQL Server: Is there an “IF EXISTS” test for a linked server?
Possible Duplicate: Join lines based on pattern I have the following file: test one
Possible Duplicate: reload (update) a .py file in the interpreter I test some of
Possible Duplicate: Ant task to check if a file exists? <target name=buildjunit> <mkdir dir=${BUILD_TEST_DIR}
Possible Duplicate: Best way to determine if two path reference to same file in
Possible Duplicate: How to test a “.xap” file on a Windows Phone 7 device?
Possible Duplicate: Open file, write to file, save file as a zip and stream

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.