Hi Team,
In my application i am checking whether a pdf file is password protected or not.
After so much R&D i am using the following function to check this.
I know this is not a straight forward method. But this was working for all the type of pdf passwords.
The application is crashing at this point : info = new PdfFileInfo(FileName);
public static bool IsPDFPasswordProtected(string FileName)
{
// bool isPassProtected = false;
// PdfFileInfo fileInfo = new PdfFileInfo(FileName);
// // determine that source PDF file is Encrypted with password
// //if (fileInfo.IsEncrypted)
// //{
// // isPassProtected = true;
// //}
// //return isPassProtected;
//// return isPassProtected = fileInfo.IsEncrypted;
// if (fileInfo.HasOpenPassword || fileInfo.HasEditPassword)
// {
// isPassProtected = true;
// }
// return isPassProtected;
bool flag = false;
PdfFileInfo info = null;
try
{
info = new PdfFileInfo(FileName);
//if (info.HasOpenPassword)
//{
// flag = true;
//}
}
catch (IOException exception)
{
if (exception.Message.ToUpper().StartsWith("BAD PASSWORD"))
{
flag = true;
}
}
catch (Exception exception2)
{
throw exception2;
}
finally
{
if (info != null)
{
try
{
info.ClearInfo();
info = null;
}
catch (Exception)
{
flag = true;
}
}
}
return flag;
}
But suddenly when i am processing the attached pdf file through this code my application is crashing.
Can you please help me on this ?
Regards
Anish
In my application i am checking whether a pdf file is password protected or not.
After so much R&D i am using the following function to check this.
I know this is not a straight forward method. But this was working for all the type of pdf passwords.
The application is crashing at this point : info = new PdfFileInfo(FileName);
public static bool IsPDFPasswordProtected(string FileName)
{
// bool isPassProtected = false;
// PdfFileInfo fileInfo = new PdfFileInfo(FileName);
// // determine that source PDF file is Encrypted with password
// //if (fileInfo.IsEncrypted)
// //{
// // isPassProtected = true;
// //}
// //return isPassProtected;
//// return isPassProtected = fileInfo.IsEncrypted;
// if (fileInfo.HasOpenPassword || fileInfo.HasEditPassword)
// {
// isPassProtected = true;
// }
// return isPassProtected;
bool flag = false;
PdfFileInfo info = null;
try
{
info = new PdfFileInfo(FileName);
//if (info.HasOpenPassword)
//{
// flag = true;
//}
}
catch (IOException exception)
{
if (exception.Message.ToUpper().StartsWith("BAD PASSWORD"))
{
flag = true;
}
}
catch (Exception exception2)
{
throw exception2;
}
finally
{
if (info != null)
{
try
{
info.ClearInfo();
info = null;
}
catch (Exception)
{
flag = true;
}
}
}
return flag;
}
But suddenly when i am processing the attached pdf file through this code my application is crashing.
Can you please help me on this ?
Regards
Anish