What code should be written so that the all pdf file can be searched on that drive and shows the preview in the same form.
What code should be written so that the all pdf file can be searched on that drive and shows the preview in the same form.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Vishal YelveRank #178 · 13.6K reputationPosted Aug 25, 2022, 12:02 AM EDT
List filePathList = new List(); foreach (DriveInfo drive in DriveInfo.GetDrives()) { try { var filenames = Directory.EnumerateFiles(drive.Name, "*.pdf", SearchOption.AllDirectories); foreach (string fileName in filenames) { filePathList.Add(fileName); } } catch (FieldAccessException ex) { //Log, handle Exception } catch (UnauthorizedAccessException ex) { //Log, handle Exception } catch (Exception ex) { //log , handle all other exceptions } }This will retrieve all the PDF files from drive