?
Solved

How to read a file

Posted on 2003-03-15
11
Medium Priority
?
129 Views
Last Modified: 2010-05-01
i need to read a file which is already opened by another process, that process also denys reading the file by another process. but i need to read that file. how to read the file using VB. can any one help me
0
Comment
Question by:maheshexp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +5
11 Comments
 
LVL 3

Expert Comment

by:DocM
ID: 8145453
Is the Input access mode OK?
Open filename For Input As 1
 a = Input(FileLen(filename), 1)
 Debug.Print a
Close
0
 

Expert Comment

by:junkeira
ID: 8145467
I dont have a straight answer.
You could try to copy this file to another directory and read it.
Usually even Windows 2000 doesnt allow us to copy or use locked files.
0
 
LVL 18

Expert Comment

by:Sethi
ID: 8145474
This code will read the text even from an open file:

Set References to Microsoft Scripting Runtime in your VB project.

Declare the following variables in Declaration section:
     Dim objFSO As FileSystemObject
Dim objTextFile As TextStream
Dim strRead as String
Fim strFileName as String
     
Create the following Sub to Write to a textfile:
Public Sub ReadFromAFile()
     Set objFSO = New FileSystemObject
     strFileName="C:\My Documents\Testing.txt"
         Set objTextFile = objFSO.OpenTextFile(strFileName, ForReading)
strRead = objTextFile.ReadAll
End Sub
'--- strFileName is the file name where you want to read the text from.
 
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8145712
Open a file depends of the type of file also. You could open as many txt files as you want (or M$ Access DBs in example) but it is not true for other types.What type of file are you trying to open? OS is a matter too.
0
 
LVL 7

Author Comment

by:maheshexp
ID: 8145734
what i want is, to open a file which is currently under windows 2000 process. the os doesn't allows me to open the file in notepad. but i want to open that file. how to do it. when i try to open the file in note pad, it says access denied.
0
 
LVL 3

Expert Comment

by:y2ksw
ID: 8147661
Open lpszFilename For Binary Access Read Shared As #1
0
 

Expert Comment

by:Chimo
ID: 8185192
If the file is opened in a mode that don't allow you to read it, you have to find the handle on that file, kill it then open it.

I have never find a way to retreive handle information for a specific files.  I have been told that it need some low level acces that VB don't have.  I'm using a freeware to get that kind of information:  http://www.sysinternals.com/ntw2k/freeware/procexp.shtml

That app also allow you to close handles.
0
 

Expert Comment

by:modulo
ID: 8426518
Dear expert(s),

A request has been made to close this Q in CS:
http://www.experts-exchange.com/Community_Support/Q_20600727.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8427684
Chimo,
if you kill the handle, how manage the file the app that have been opening it in first place?
0
 

Expert Comment

by:Chimo
ID: 8427746
Maheshexp wanted to know how to open a locked file using VB.  So to do that I think the only way is to kill the locking handle on that file.  I didn't mention it, but yes it can lead to serious problem for the application that had a lock on that file.

Maybe in assembler you can read it even if it locked, but I think the locking process is handled by the OS and it will deny any code that will try to read, delete, write, ... to that file.  But my asembler and OS knowledge on that subject is far behind me and the question require to use VB.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8449361
Saving this Q as a PAQ and refunding the 100 points to the questionner

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month13 days, 5 hours left to enroll

777 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