We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Open Password Protected power point documents

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I am using Aspose.Slides to read contents from PowerPoint document. I am using below code to open the password protected documents using Aspose.Slides.

try

{

PresentationEx presentation = new PresentationEx(m_documentFile)}

catch (Exception ex)

{

if (ex.Message.Contains("Presentation is encrypted"))

{

LoadOptions loadOps = new LoadOptions();

loadOps.Password = m_passwordList[0] as string;

presentation = new PresentationEx(m_documentFile, loadOps);

}

else

throw ex;

}

But my current requirement is to loop the list of passwords provided by the user and try to open the document utile the document opens sccessfully.

Please provide the sample code for this as soon as possible.

Thanks,

Dhivyav

Hi Dhivyav,

I have observed the requirements shared by you and have generated the following sample code for your convenience. The attached code will allow you to traverse through different passwords for loading a password protected presentation.

public static void TestPass()
{
List passwords = new List();
passwords.Add(“Test1”);
passwords.Add(“Test2”);
passwords.Add(“Test3”);
passwords.Add(“Test4”);
String m_documentFile = “D:\Aspose Data\TestPres.pptx”;
PresentationEx presentation = null;
try
{
presentation = new PresentationEx(m_documentFile);
}
catch (Exception ex)
{
if (ex.Message.Contains(“Presentation is encrypted”))
{
foreach (String pass in passwords)
{
LoadOptions loadOps = new LoadOptions();
// loadOps.Password = m_passwordList[0] as string;
loadOps.Password = pass;
try
{
presentation = new PresentationEx(m_documentFile, loadOps);
break;
}
catch (InvalidPasswordException ExPass)
{
continue;
}
}
}

else
throw ex;

}
presentation.Save(m_documentFile + “.pdf”, SaveFormat.Pdf);
}

Please share, if I may help you further in this regard.

Many Thanks,

Hi,

If I try to open password protected (*.ppt) document from stream using Aspose.Slides.Presentation, it is throughing "IndexOutOfRangeException". Please find the below code for your reference.

Presentation presentation = null;

List _passwordList = new List();
passwords.Add("Test1");
passwords.Add("Test2");
passwords.Add("Test3");
passwords.Add("Test4");

try { presentation = new Presentation(stream); }

catch {

LoadOptions loadOps = new LoadOptions();

foreach (string pass in _passwordList)

{try

{

loadOps.Password = pass;

presentation = new Presentation(stream, loadOps);

break;

}

catch { continue; }

}

}

Thanks,Dhivya

Hi Dhivyav,


Thanks for your feedback. Can you please provide us the source presentation as I need to investigate this on my end. Please also share the password for the source presentation as well.

Many Thanks,

Hi,

Please find the attached document for your reference. The password to open the document is "Dhivya".

Thanks,

Dhivya

Hi Dhivya,


I have observed that you are using PPT on your end. I like to share that you need Presentation class to load PowerPoint 97~2003 presentation formats (PPT, PPS and POT) and PresentationEx class for PowerPoint 2007~2013 presentation formats (PPTX, PPSX and POTX). Please use the following sample code on your end to load the PPT presentations. Please share, if I may help you further in this regard.

public static void TestPass()
{
List passwords = new List();
passwords.Add(“Test1”);
passwords.Add(“Test2”);
passwords.Add(“Test3”);
passwords.Add(“Dhivya”);
String m_documentFile = “C:\Presentations\Report_Pass.ppt”;
Presentation presentation = null;
try
{
presentation = new Presentation(m_documentFile);
}
catch (Exception ex)
{
if (ex.Message.Contains(“Presentation is encrypted”) || ex.Message.Contains(“Wrong password.”))
{
foreach (String pass in passwords)
{
LoadOptions loadOps = new LoadOptions();
// loadOps.Password = m_passwordList[0] as string;
loadOps.Password = pass;
try
{
presentation = new Presentation(m_documentFile, loadOps);
break;
}
catch (InvalidPasswordException ExPass)
{
continue;
}
}
}

else
throw ex;

}
presentation.Save(m_documentFile + “.pdf”, SaveFormat.Pdf);
}


Many Thanks,

Hi Mudassir ,

If I use string file path in presentation it is working fine. But if I use file stream instead of file path, that time I am facing the above mentioned issue.

I am converting the file to file stream, then passing it into presentation object.

String m_documentFile = "C:\\Presentations\\Report_Pass.ppt";

Presentation presentation = null;

FileStream fs = File.OpenRead(m_documentFile);

LoadOptions loadOps = new LoadOptions();

// loadOps.Password = m_passwordList[0] as string;
loadOps.Password = pass;

presentation = new Presentation(fs, loadOps);

Please find the above code for your testing purpose.

Thanks,

Dhivya

Hi Dhivya,

I have observed the sample code shared. Please try using the following sample code on your end to serve the purpose. You actually need to position the FileStream position to 0 on every read.

public static void TestPassPPT()
{
List passwords = new List();
passwords.Add(“Test1”);
passwords.Add(“Test2”);
passwords.Add(“Test3”);
passwords.Add(“Dhivya”);
String m_documentFile = “D:\Aspose Data\Report_Pass.ppt”;
Presentation presentation = null;


FileStream fs = File.OpenRead(m_documentFile);
try
{
fs.Position = 0;
presentation = new Presentation(fs);
}
catch (Exception ex)
{
if (ex.Message.Contains(“Presentation is encrypted”) || ex.Message.Contains(“Wrong password.”))
{
foreach (String pass in passwords)
{
LoadOptions loadOps = new LoadOptions();
// loadOps.Password = m_passwordList[0] as string;
loadOps.Password = pass;
try
{
fs.Position = 0;
presentation = new Presentation(fs, loadOps);
break;
}
catch (InvalidPasswordException ExPass)
{
continue;
}
}
}

else
throw ex;

}
presentation.Save(m_documentFile + “.pdf”, SaveFormat.Pdf);
}

Many Thanks,