Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this methode convert single tiff to 32 jpeg images

void IMAGE(string strFilePath)
{
string PathForCopy = string.Empty;
string folderName = string.Empty;
string TeacherId = string.Empty;
string directoryPath = string.Empty;
TeacherId = Convert.ToString(Session["TeacherId"]);
Bitmap bmap = null;
Session["UrlListForHe"] = null;
try
{
List<system.drawing.image> lst = new List<system.drawing.image>();

if (strFilePath != string.Empty)
{

string strFilename = System.IO.Path.GetFileNameWithoutExtension(strFilePath);
if (strFilename != "")
{
string strpagename = string.Empty;
if (File.Exists(strFilePath))
{
bmap = (Bitmap)System.Drawing.Image.FromFile(strFilePath);
int max = bmap.GetFrameCount(FrameDimension.Page);
float icount = (float)100 / max;
folderName = ConfigurationManager.AppSettings["FolderToViewPagesForEvaluator"].ToString();
PathForCopy = folderName + TeacherId;
if (!Directory.Exists(Server.MapPath(PathForCopy)))
{
Directory.CreateDirectory(Server.MapPath(PathForCopy));
}

int i;
for (i = 0; i < max; i++)
{
bmap.SelectActiveFrame(FrameDimension.Page, i);
strpagename = strFilename + "Page" + i.ToString().Trim();
lst.Add((System.Drawing.Image)bmap.Clone());
string url = Server.MapPath(PathForCopy) + "/00" + i.ToString() + ".Jpeg";
string Imgurl = PathForCopy + "/00" + i.ToString() + ".Jpeg";
(lst[i] as System.Drawing.Image).Save(url, ImageFormat.Jpeg);
strpath.Add(Imgurl);

}
Session["UrlListForHe"] = strpath;
lblPageCount.Text = strpath.Count().ToString();
TextBox1.Text = "1";
Image1.ImageUrl = strpath[0].ToString() + "?" + DateTime.Now.Ticks.ToString() ;
btnpre.Enabled = false;
btnnext.Enabled = true;
bmap.Dispose();
}
else
{
btnpre.Enabled = false;
btnnext.Enabled = false;
TextBox1.Text = "0";
lblPageCount.Text = "";
Image1.ImageUrl = "~/Images/FileNotFound.png";
bmap.Dispose();
}
}
else
{
btnpre.Enabled = false;
btnnext.Enabled = false;
TextBox1.Text = "0";
lblPageCount.Text = "";
Image1.ImageUrl = "~/Images/FileNotFound.png";
bmap.Dispose();
}
}
}


methode for deleting tiff image

C#
public bool DeleteMarksAndCopyForRecheck(string roll, string subject, string bar,string path,out string msg)
       {
           // A= File Not Found !
           // B= Data Not deleted !
           // C=Exception !
           // D=Success !
           bool flag = false;
           msg = string.Empty;
           string str = "exec SetIsEvaluatedZero " + roll + " , '" + subject + "' , '" + bar + "'";
           path = HttpContext.Current.Server.MapPath(path);
           string ReplacePathForPopUp = ConfigurationManager.AppSettings["ReplacePathForCopyRecheckPopUp"];

           string Newpath = path.Replace(ReplacePathForPopUp, "");

           try
           {
               if (System.IO.File.Exists(Newpath))
               {
                   File.Delete(Newpath);
                   if (!(System.IO.File.Exists(Newpath)))
                   {
                       dt = ClsConObj.ExecuteProcedureREturnTable(str);
                       if (dt.Rows[0]["msg"].ToString().Trim() == "YES".Trim())
                       {
                           flag = true;
                           msg = "D";
                       }
                       else
                       {
                           flag = false;
                           msg = "B";
                       }
                   }
               }
               else
               {
                   flag = false;
                   msg = "A";
               }
           }
           catch (Exception ex)
           {
               flag = false;
               msg = "C";


           }
           return flag;
       }
Posted

1 solution

Try to use my advice from my past answer: File used by another process exception[^].

—SA
 
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