Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using the following code block to extract data from image through OCR:

C#
MODI.Document tifDoc = new Document();
                            tifDoc.Create(Server.MapPath("~/Upload/") + fname.Split('.')[0] + ".tif");
                            tifDoc.OCR(MiLANGUAGES.miLANG_SYSDEFAULT, false, false);
                            tifDoc.Save();
                            MODI.Image tifImg = (MODI.Image)tifDoc.Images[0];
                            content += tifImg.Layout.Text;
                            tifDoc.Close(false);
                            tifDoc = null;
                            tifImg = null;
                            GC.Collect();
                            GC.WaitForPendingFinalizers();


But when i try to delete the tiff image, it throws an exception that The process cannot access the file because it is being used by another process . What do I do?
Posted
Comments
Kenneth Haugland 11-Aug-12 4:58am    
The code does not make sence to me in regards to the question you pose. Why save the file if you want to delete it? Could you elaborate?
Member 8491154 13-Aug-12 0:30am    
I want to delete the file because i dont to store it on my server. I just want to keep the extracted text.
AmitGajjar 11-Aug-12 5:26am    
use Using keyword to dispose MODI.Document. if Document class inherits IDisposable.
Member 8491154 13-Aug-12 0:29am    
can you please elaborate on your code?
AmitGajjar 13-Aug-12 0:33am    
http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.80%29.aspx please check this MSDN article for how you can dispose your object with using keyword.

1 solution

you have to do folloing methos before delete that file
C#
tifDoc.dispose();

after disposing that item can be deleted successfully.
 
Share this answer
 
v2
Comments
Member 8491154 17-Aug-12 4:59am    
There is no method as dispose for MODI.Document
Leo Rajendra Dhakal 17-Aug-12 7:52am    
I mean that which instance was created to use you have to dispose or destroy that items other wise you are unable to remove or delete because system is using that item.
Member 8491154 17-Aug-12 8:53am    
I know this. I have destroyed it by setting null in its value. But, still it is not destroyed.

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