Click here to Skip to main content
15,905,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys.....

I need help , I want to know Process Name which is using a file.

Ex. I want to know file ABC.txt is opened by which Process.


Actually i want this because, I am doing Continuous Printing , the steps I am doing is following

STEP1 : Checking If Rich1.txt Exist or not if Yes, then I am deleting it first , then Creating new txt with Name Rich1.txt

Step 2: Now writing characters using streamwriter. After writing Characters i am closing Closing streamwriter

Step3 After writing Rich1.txt Sending it to RawPrinter(Printer)


But the Real Problem is that when i Do continuous Printing (One after One)
then first time it is Printing ok , But when it comes for second time
then it is throwing exception at step1 that C:\Rich1.txt is used by another Process

I am unable to konow which process is using it . I look in Taskmanager for notepad.exe ( because .txt is opened by notepad ) but i not got.

Any Help is Welcome.....!
Posted

The chances are it is in use by your own application.
First thing to do is to use Dispose on any and all streams in your app - Close may not be sufficient.
Secondly, if that doesn't fix it, then there is a very good chance that the RawPrinter has the file open until it is completely finished with the print out.

Try this: Remove the RawPrinter stuff from your code for testing - does the problem still persists? If it doesn't, then you know where the problem is - you will have to wait until the print is complete somehow.
 
Share this answer
 
Comments
Varinder Raii 30-Mar-12 11:36am    
If i remove RawPrinter stuff then how i will send document to printer
OriginalGriff 30-Mar-12 11:55am    
"Remove the RawPrinter stuff from your code for testing" - the last two words are important! :laugh:
The idea is to find out what is causing the problem. If you can't do that, you can't guarantee to have fixed it...
Varinder Raii 31-Mar-12 4:17am    
Sorry i was frustrated with this problem thats why i not got what you say.
Thanks For your Reply
what is vb.net .why do we use of vb.net./pre>>
 
Share this answer
 
Comments
El_Codero 31-Mar-12 6:54am    
ahh okay, nice solution!
Varinder Raii 31-Mar-12 7:16am    
sorry, I didn't get ??
I solve it Problem by using two textDocument For Ex. Rich1.txt and Rich2.txt and

When i checked for File Rich1.txt if it exist ? here, it is giving exception . I put this code in try Catch and when Control goes to Catch Line then I start writing Rich2.txt
and Send it to Printer.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900