473,756 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MODI - Cannot delete file after document closed

I am using Microsoft Office Document Imaging (MODI) with great success.
However, when execute the following code, I get the error "The process
cannot access the file 'myFile.tif'" (File name has been shortened).

Here is the code I am using:
-- BEGIN CODE --
public class OCRUtil : IDisposable
{
const string FILENAME = "myFile.tif ";
private MODI.Document doc = null;

/// <summary>
/// Initializes a new instance of the OCRUtil class.
/// </summary>
public OCRUtil(string filePath)
{
doc = new MODI.Document() ;
doc.Create(file Path);
doc.OCR(MODI.Mi LANGUAGES.miLAN G_SYSDEFAULT, true, true);
// Using SaveAs() rather than Save() so that if other classes
// wish to use the same file, we don't have to worry about a
// contention.
doc.SaveAs(FILE NAME, MODI.MiFILE_FOR MAT.miFILE_FORM AT_TIFF,
MODI.MiCOMP_LEV EL.miCOMP_LEVEL _HIGH);
}

public int GetImageCount()
{
return doc.Images.Coun t;
}

public void Dispose()
{
doc.Close(false );
doc = null;
GC.Collect();
if (File.Exists(FI LENAME))
{
File.Delete(FIL ENAME);
}
}
}

[TestFixture]
public class OCRUtilTests
{
private string _filePath = @"..\..\2PageJo urnalFax.tif";
[Test]
public void TestOCRCount()
{
OCRUtil ocr = new OCRUtil(_filePa th);

Assert.AreEqual (2, ocr.GetImageCou nt());

ocr.Dispose();
}
}

-- END CODE --

Here is the whole error message:

-- BEGIN ERROR MESSAGE --
TestCase 'Kahuna.OCR.Tes ts.OCRUtilTests .TestOCRRead'
failed: System.IO.IOExc eption : The process cannot access the file
'D:\_Code\_Appl ications\Kahuna OCR\Kahuna.OCR. Tests\bin\Debug \myFile.tif'
because it is being used by another process.
at System.IO.__Err or.WinIOError(I nt32 errorCode, String maybeFullPath)
at System.IO.File. Delete(String path)
D:\_Code\_Appli cations\KahunaO CR\Kahuna.OCR\O CRUtil.cs(47,0) : at
Kahuna.OCR.OCRU til.Dispose()
D:\_Code\_Appli cations\KahunaO CR\Kahuna.OCR.T ests\OCRUtilTes ts.cs(21,0):
at Kahuna.OCR.Test s.OCRUtilTests. TestOCRRead()
-- END ERROR MESSAGE --

Any ideas on how I can get the Document object to release its evil grip
on my defenseless file?

Thank you for your time.

Tod Birdsall, MCSD for .NET
blog: http://tod1d.net

Aug 15 '06 #1
1 8901
I have found a work around for this issue. You can read about it by
viewing this thread:

http://shrinkster.com/hh3

--
Tod Birdsall, MCSD for .NET
blog: http://tod1d.net
Tod Birdsall wrote:
I am using Microsoft Office Document Imaging (MODI) with great success.
However, when execute the following code, I get the error "The process
cannot access the file 'myFile.tif'" (File name has been shortened).

Here is the code I am using:
-- BEGIN CODE --
public class OCRUtil : IDisposable
{
const string FILENAME = "myFile.tif ";
private MODI.Document doc = null;

/// <summary>
/// Initializes a new instance of the OCRUtil class.
/// </summary>
public OCRUtil(string filePath)
{
doc = new MODI.Document() ;
doc.Create(file Path);
doc.OCR(MODI.Mi LANGUAGES.miLAN G_SYSDEFAULT, true, true);
// Using SaveAs() rather than Save() so that if other classes
// wish to use the same file, we don't have to worry about a
// contention.
doc.SaveAs(FILE NAME, MODI.MiFILE_FOR MAT.miFILE_FORM AT_TIFF,
MODI.MiCOMP_LEV EL.miCOMP_LEVEL _HIGH);
}

public int GetImageCount()
{
return doc.Images.Coun t;
}

public void Dispose()
{
doc.Close(false );
doc = null;
GC.Collect();
if (File.Exists(FI LENAME))
{
File.Delete(FIL ENAME);
}
}
}

[TestFixture]
public class OCRUtilTests
{
private string _filePath = @"..\..\2PageJo urnalFax.tif";
[Test]
public void TestOCRCount()
{
OCRUtil ocr = new OCRUtil(_filePa th);

Assert.AreEqual (2, ocr.GetImageCou nt());

ocr.Dispose();
}
}

-- END CODE --

Here is the whole error message:

-- BEGIN ERROR MESSAGE --
TestCase 'Kahuna.OCR.Tes ts.OCRUtilTests .TestOCRRead'
failed: System.IO.IOExc eption : The process cannot access the file
'D:\_Code\_Appl ications\Kahuna OCR\Kahuna.OCR. Tests\bin\Debug \myFile.tif'
because it is being used by another process.
at System.IO.__Err or.WinIOError(I nt32 errorCode, String maybeFullPath)
at System.IO.File. Delete(String path)
D:\_Code\_Appli cations\KahunaO CR\Kahuna.OCR\O CRUtil.cs(47,0) : at
Kahuna.OCR.OCRU til.Dispose()
D:\_Code\_Appli cations\KahunaO CR\Kahuna.OCR.T ests\OCRUtilTes ts.cs(21,0):
at Kahuna.OCR.Test s.OCRUtilTests. TestOCRRead()
-- END ERROR MESSAGE --

Any ideas on how I can get the Document object to release its evil grip
on my defenseless file?

Thank you for your time.

Tod Birdsall, MCSD for .NET
blog: http://tod1d.net
Aug 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4545
by: jhazucha | last post by:
Im using C# and MODI, I can get the document into my application with eas' but the only way I can see to tell it what data I actually need from the document is to use the MiDocView. now I dont want that. im basically trying to automate this so that the app run's .. looks thru a directory grabs all the scanned documents which are all the same form layout's and grab the PO Number from the upper right and then export the data to a text file...
3
12294
by: David de Passos | last post by:
Hi! I'm using MODI activex from Microsoft Office 2003 and Microsoft VB.NET to get the text from an OCR acquired image. Why after OCR the image, the MODI component rotate the image? Sometimes the MODI rotates the image 90 degrees and the OCR, obviously, can' t do its job. Any ideia why this is happening?
0
1377
by: | last post by:
Hello I have a MODI (Microsoft Office Document Imaging) document and I want to show thumbnails form all the pages in the document on a form. How can i put a MODI-Image into a Picturebox using vb.net? Thank you a lot Stefan
0
1898
by: Pedro Hurtado | last post by:
I am using (Microsoft Office Document Imaging 11.0 Type Library) and I have the following problem: The method (Microsoft Office Document Imaging 11.0 Type Library) of the interface IImage me an object type stdole.IPictureDisp, that i can transform to System.Drawing.Image with the static method System.Drawing.Image.FromHbitmap, when step the Picture property of the same form gives an error me of type exception
1
2080
by: hangdee | last post by:
I am trying to use MODI (Microsoft Office Document Imaging) viewer control in my VB 2005 application. But when I drag the MODI viewer control into my form, it prompts that "Failed to import the ActiveXcontrol. Please ensure it is properly registered" What is the problem? I want to use the MODI viewer to show tiff file, please help
0
1806
by: fyderniX | last post by:
Hey; I'm using the Document Imagine API from Office 2003. I need to get away from the proprietary MDI/TIFF formats it produces. It looked pretty simple, but it's giving me grief when I try to convert the IPictureDisp object it creates into an Image for use with .NET: -----begin source (C#)----- //Take page 1 MODI.Image page_1 = (MODI.Image) doc.Images;
0
1820
by: surezu sanmugam | last post by:
Hi all, i have to developing a document processing project using microsoft office document imaging(MODI) library in visual studio 2005. My problem is when i adding MODI viewer control to the toolbox and drag it into windows form,it will thrown "Failed to import the activex control.Please ensure it is properly registered" error..please let me right what i did wrong.. thanks in advance
2
15007
by: SCPOS | last post by:
Cannot delete X: It is being used by another person or program. Close any programs that might be using the file and try again. Of course I have tried closing any programs I know of that may be using the file (used X because the filename does not matter...it is a specific log file name to the application). I am logged onto a Windows Server 2003 computer that acts as a server for a LAN, but is physically joined to a domain. The local...
2
4824
by: sphinney | last post by:
Hi everyone. I have a form in my Access 2007 database with a Microsoft Office Document Imaging Viewer Control 12.0 object on it. The object is named "GRAPHIC_mdv". When the form opens I want to take the path and filename information passed to the form (via the form's opening arguements) and display the file in the MODI Viewer Control object. I'm using the following code to do this: Private Sub Form_Open(Cancel As Integer) Dim miDOC As...
0
10014
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9689
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7226
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6514
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3780
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2647
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.