Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
While checking file I wants to delete file

C#
public void CheckFileType(string directoryPath)
       {
           IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();
           while (files.MoveNext())
           {

               //get file extension
               string fileExtension = Path.GetExtension(Convert.ToString(files.Current));

               //get file name without extenstion
               string fileName = Convert.ToString(files.Current).Replace(fileExtension, string.Empty);

               //Check for JPG File Format
               if (fileExtension == ".tiff" || fileExtension == ".TIFF") // or // ImageFormat.Jpeg.ToString()
               {
                   try
                   {
                       //OCR Operations ...

                       MODI.Document md = new MODI.Document();
                       md.Create(Convert.ToString(files.Current));
                       md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
                       string myText = "";
                       for (int i = 0; i < md.Images.Count; i++)
                       {
                           MODI.Image image = (MODI.Image)md.Images[i];

                           myText = myText + image.Layout.Text.ToString();

                       }


                     txtPatientNm.Text = Extracttext(myText).ToString();


                   }
                   catch (Exception)
                   {

                   }
               }
           }
       }
Posted
Updated 29-Sep-11 20:28pm
v3

To delete a file use :

C#
File.Delete("filename.ext");
 
Share this answer
 
Comments
anjali2 30-Sep-11 2:35am    
err = {"The process cannot access the file 'c:\\TempDownloads\\ImageFiles\\15.tiff' because it is being used by another process."}
Mehdi Gholam 30-Sep-11 2:39am    
Your file is still open presumably by the md object, see if the MODI.Document has a close file method before using File.Delete
sravani.v 30-Sep-11 2:39am    
May be u r trying to delete already opened file.

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