?
Solved

Open Files

Posted on 2011-10-20
6
Medium Priority
?
158 Views
Last Modified: 2012-05-12
I'm using the following code to verify if a file is open by any application, it works in some file but the .txt files  and MS word file don't work it tell me that they are free.

What could be
Try

            Dim FS As IO.FileStream = IO.File.Open(FileName, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
        
            FS.Close()
            FS.Dispose()
            FS = Nothing
            open = False ' 'Free file

        Catch ex As IO.IOException
            open = True ' 'Busy File
        Catch ex As Exception
                     
        End Try

Open in new window

0
Comment
Question by:cano63
  • 3
  • 2
6 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 37001330
Applications typically don't lock a file, especially a txt file.
0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 37001478
+1
Applications typically don't lock a file, especially a txt file.
0
 
LVL 1

Author Comment

by:cano63
ID: 37001684
And how i can know if a file i open by other application
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 37002121
Hello cano63, by using your code you can know when an application currently has active handler over the file, when strickdd said "Applications typically don't lock a file, especially a txt file." that means the application open the file, reads it to the memory, then closes the file, releasing any handler, so you must understand that in first place, then you can explore another ways to achieve what you want to do.
0
 
LVL 1

Author Comment

by:cano63
ID: 37019926
Thanks,

But I try to run the code in a notepad and the system tell me that is not used by any one, but if I use a word pefect document it work.

Why is the diference
0
 
LVL 17

Accepted Solution

by:
Carlos Villegas earned 500 total points
ID: 37020036
Hello, because windows notepad work in that way (open, read the content and closes it), that behavior is not a rule, all depend in how an application is developed, I think that a word perfect document has a more complex format that a txt file, so is not a good idea to load it to the memory at once.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question