bool b = false;
KIA obj = new KIA();
string[] filePaths = Directory.GetFiles(MapPath("~/View/CertificationAgency/KIACertificate/Certificates/"));
DirectoryInfo target = new DirectoryInfo(MapPath("~/View/CertificationAgency/KIACertificate/FinalCertificates/"));
try
{
foreach (string s in filePaths)
{
if (Path.GetExtension(s).ToUpper().Equals(".PDF"))
{
string onlyfilename = Path.GetFileName(s).ToUpper();
string withoutexten = Path.GetFileNameWithoutExtension(s);
if (onlyfilename == MappingRecord(withoutexten) + ".PDF")
{
obj.InsertCertificate(onlyfilename, new Random().Next().ToString(), withoutexten);
File.Move(MapPath("~/View/CertificationAgency/KIACertificate/Certificates/") + withoutexten + ".PDF", MapPath("~/View/CertificationAgency/KIACertificate/FinalCertificates/" + onlyfilename));
System.Threading.Thread.Sleep(1);
File.Delete(MapPath("~/View/CertificationAgency/KIACertificate/Certificates/" + onlyfilename));
}
}
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Mapping Completed');", true);
}
catch (DirectoryNotFoundException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (ArgumentException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (IOException ex)
{
foreach (string s in filePaths)
{
if (Path.GetExtension(s).ToUpper().Equals(".PDF"))
{
string onlyfilename = Path.GetFileName(s).ToUpper();
string withoutexten = Path.GetFileNameWithoutExtension(s);
if (onlyfilename == MappingRecord(withoutexten) + ".PDF" && File.Exists(MapPath("~/View/CertificationAgency/KIACertificate/FinalCertificates/" + onlyfilename)))
{
System.Threading.Thread.Sleep(1);
File.Delete(MapPath("~/View/CertificationAgency/KIACertificate/Certificates/" + onlyfilename));
}
}
}
b = true;
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
if (b)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Duplicate Record Deleted Sucessfully');", true);
}
GC.Collect();
GC.SuppressFinalize(this);
}
No comments:
Post a Comment