473,324 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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(filePath);
doc.OCR(MODI.MiLANGUAGES.miLANG_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(FILENAME, MODI.MiFILE_FORMAT.miFILE_FORMAT_TIFF,
MODI.MiCOMP_LEVEL.miCOMP_LEVEL_HIGH);
}

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

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

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

Assert.AreEqual(2, ocr.GetImageCount());

ocr.Dispose();
}
}

-- END CODE --

Here is the whole error message:

-- BEGIN ERROR MESSAGE --
TestCase 'Kahuna.OCR.Tests.OCRUtilTests.TestOCRRead'
failed: System.IO.IOException : The process cannot access the file
'D:\_Code\_Applications\KahunaOCR\Kahuna.OCR.Tests \bin\Debug\myFile.tif'
because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Delete(String path)
D:\_Code\_Applications\KahunaOCR\Kahuna.OCR\OCRUti l.cs(47,0): at
Kahuna.OCR.OCRUtil.Dispose()
D:\_Code\_Applications\KahunaOCR\Kahuna.OCR.Tests\ OCRUtilTests.cs(21,0):
at Kahuna.OCR.Tests.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 8886
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(filePath);
doc.OCR(MODI.MiLANGUAGES.miLANG_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(FILENAME, MODI.MiFILE_FORMAT.miFILE_FORMAT_TIFF,
MODI.MiCOMP_LEVEL.miCOMP_LEVEL_HIGH);
}

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

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

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

Assert.AreEqual(2, ocr.GetImageCount());

ocr.Dispose();
}
}

-- END CODE --

Here is the whole error message:

-- BEGIN ERROR MESSAGE --
TestCase 'Kahuna.OCR.Tests.OCRUtilTests.TestOCRRead'
failed: System.IO.IOException : The process cannot access the file
'D:\_Code\_Applications\KahunaOCR\Kahuna.OCR.Tests \bin\Debug\myFile.tif'
because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Delete(String path)
D:\_Code\_Applications\KahunaOCR\Kahuna.OCR\OCRUti l.cs(47,0): at
Kahuna.OCR.OCRUtil.Dispose()
D:\_Code\_Applications\KahunaOCR\Kahuna.OCR.Tests\ OCRUtilTests.cs(21,0):
at Kahuna.OCR.Tests.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
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...
3
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? ...
0
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...
0
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...
1
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...
0
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...
0
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...
2
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...
2
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.