Document passwords
The PasswordDictionary class is designed to store passwords for documents to be indexed. Information on indexing password protected documents is presented on the Indexing password protected documents page.
To get the number of passwords in the dictionary, use the Count property.
To get the password for a document from the dictionary, the GetPassword method is used, passing the path to the document as an argument.
The Clear method is used to remove all passwords from the dictionary.
To check for the presence of a password in the dictionary for the specified document, the Contains method is used.
To add a password to the dictionary, use the Add method. The key is the path to the document.
To remove a password from the dictionary, use the Remove method.
The following example demonstrates the use of methods of the password dictionary.
C#
string indexFolder = @"c:\MyIndex\";
// Creating an index from in specified folder
Index index = new Index(indexFolder);
if (index.Dictionaries.DocumentPasswords.Count > 0)
{
// Removing all passwords from the dictionary
index.Dictionaries.DocumentPasswords.Clear();
}
string path = Path.GetFullPath(@"c:\MyIndex\Protected.pdf");
if (index.Dictionaries.DocumentPasswords.Contains(path))
{
// Getting a password for a document
string password = index.Dictionaries.DocumentPasswords.GetPassword(path);
Console.WriteLine(path);
Console.WriteLine("\tPassword: " + password);
// Deleting the password from the dictionary
index.Dictionaries.DocumentPasswords.Remove(path);
}
// Adding a password for a document
index.Dictionaries.DocumentPasswords.Add(path, "123456");
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples:
Free online document search App
Along with full featured .NET library we provide simple, but powerful free Apps.
You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.