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.
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; } } }
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");
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.
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.
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.
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; } } }
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.