how to delete temparary files in c:\TempDownloads\TempFiles\
public partial class Attach_Download : Form
{
public Attach_Download()
{
InitializeComponent();
}
private void btnDownload_Click(object sender, EventArgs e)
{
}
private void Attach_Download_Load(object sender, EventArgs e)
{
try
{
lbldate.Text=System.DateTime.Now.ToLongDateString();
Directory.Delete(@"C:\TempDownloads", true);
}
catch (Exception err)
{
}
using (Imap imap = new Imap())
{
imap.Connect("smtp.ascent-group.com");
imap.Login("software@ascent-group.com", "ascent44");
imap.SelectInbox();
List<long> uids = imap.SearchFlag(Flag.All);
if (uids.Count < 1)
{
txtNoFax.Text = "MailBox is empty";
}
else
{
txtNoFax.Text = uids.Count.ToString();
}
}
}
public void createPatientList()
{
string dirStr2 = "c:/PatientList2";
if (Directory.Exists(dirStr2))
{
}
else
{
Directory.CreateDirectory(dirStr2);
}
string str1 = "c:/TempDownloads/ImageFiles";
if (Directory.Exists(str1))
{
}
else
{
Directory.CreateDirectory(str1);
}
string str2 = "c:/TempDownloads/TempFiles";
if (Directory.Exists(str2))
{
}
else
{
Directory.CreateDirectory(str2);
}
}
public static string Extracttext(string Url)
{
if (Url.Contains(@"Patient Name: "))
{
Url = Url.Split(new string[] { "Patient Name: " }, 2, StringSplitOptions.None)[1];
}
else if (Url.Contains(@"Pt. Name: "))
{
Url = Url.Split(new string[] { "Pt. Name: " }, 2, StringSplitOptions.None)[1];
}
else if (Url.Contains(@"PATIENT NAME: "))
{
Url = Url.Split(new string[] { "PATIENT NAME: " }, 2, StringSplitOptions.None)[1];
}
else if (Url.Contains(@"PATIENT: "))
{
Url = Url.Split(new string[] { "PATIENT: " }, 2, StringSplitOptions.None)[1];
}
else
{
Url = "";
}
return Url.Split('\r')[0];
}
private void btnsave_Click(object sender, EventArgs e)
{
lblmessage.Text = "Please wait while Downloading Faxes";
string dirStr = "c:/Downloads2";
string currentdt = String.Format("{0:dd-MM-yyyy}", System.DateTime.Now);
string str = "c:/Downloads2/" + currentdt.ToString();
string dirStr2 = "c:/TempDownloads/TempFiles";
if (Directory.Exists(dirStr))
{
}
else
{
Directory.CreateDirectory(dirStr);
}
if (Directory.Exists(str))
{
}
else
{
Directory.CreateDirectory(str);
}
if (Directory.Exists(str))
{
using (Imap imap = new Imap())
{
imap.Connect("smtp.ascent-group.com");
imap.Login("software@ascent-group.com", "ascent44");
imap.SelectInbox();
List<long> uids = imap.SearchFlag(Flag.All);
if (uids.Count < 1)
{
MessageBox.Show("MailBox is empty");
}
else
{
foreach (long uid in uids)
{
string eml = imap.GetMessageByUID(uid);
IMail email = new MailBuilder()
.CreateFromEml(eml);
email.Attachments.ForEach(mime => mime.Save(str + "/" + mime.SafeFileName));
createPatientList();
email.Attachments.ForEach(mime => mime.Save(dirStr2 + "/" + +uid + ".pdf"));
string path = @"c:\TempDownloads\TempFiles\" + uid + ".pdf";
using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
{
document = new Document(file);
}
ConvertToTiffOptions tiffOptions = new ConvertToTiffOptions(getDPI(), getCompression());
string tiffile = @"c:\TempDownloads\ImageFiles\" + uid + ".tiff";
using (FileStream file = new FileStream(tiffile, FileMode.Create, FileAccess.Write))
{
document.ConvertToTiff(file, tiffOptions);
file.Close();
}
try
{
CheckFileType(@"c:\TempDownloads\ImageFiles\");
string ln = "";
string Message = txtPatientNm.Text.ToString();
string[] Record = Regex.Split(Message.Trim(), " ");
ln = Record[1].ToString();
string fn = Record[0].ToString();
string strPList = "c:/PatientList2/";
if (ln != "" && fn != "")
{
email.Attachments.ForEach(mime => mime.Save(strPList + "/" + ln + "-" + fn + ".pdf"));
}
else
{
email.Attachments.ForEach(mime => mime.Save(strPList + "/" + mime.SafeFileName));
}
}
catch (Exception err)
{
string strPList = "c:/PatientList2/";
email.Attachments.ForEach(mime => mime.Save(strPList + "/" + mime.SafeFileName));
}
}
imap.Close();
MessageBox.Show("Attachment downloaded successfully....");
lblmessage.Text = "";
btnsave.Enabled = false;
}
}
}
}
int getDPI()
{
return 96;
throw new Exception("Unsupported DPI selected.");
}
TiffCompression getCompression()
{
return TiffCompression.None;
throw new Exception("Unsupported Compression selected.");
}
Document document = null;
public void CheckFileType(string directoryPath)
{
IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();
while (files.MoveNext())
{
string fileExtension = Path.GetExtension(Convert.ToString(files.Current));
string fileName = Convert.ToString(files.Current).Replace(fileExtension, string.Empty);
if (fileExtension == ".tiff" || fileExtension == ".TIFF")
{
try
{
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)
{
}
}
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}