private Stream ReadPdfStreamFromExternalStorage()
{
//Get the path of external storage directory. Here we used download directory to read PDF document
String path = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath;
//Read the specific PDF document from the download directory
Java.IO.File filePath = new Java.IO.File(path+"/test.pdf");
// Check whether the file is exist in the download directory
if (filePath.Exists())
{
// Convert the file path to stream to display it into SfPdfViewer
return new FileStream(filePath.AbsolutePath, FileMode.Open, FileAccess.Read);
}
else
{
// throw exception if the file is not found in the appropriate directory
throw new FileNotFoundException("File not found"+ filePath.AbsolutePath.ToString());
}
} |
private Stream ReadPdfStreamFromExternalStorage() { //Get the path of external storage directory. Here we used download directory to read PDF document String path = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath; //Read the specific PDF document from the download directory Java.IO.File filePath = new Java.IO.File(path+"/test.pdf"); // Check whether the file is exist in the download directory if (filePath.Exists()) { // Convert the file path to stream to display it into SfPdfViewer return new FileStream(filePath.AbsolutePath, FileMode.Open, FileAccess.Read); } else { // throw exception if the file is not found in the appropriate directory throw new FileNotFoundException("File not found"+ filePath.AbsolutePath.ToString()); } } |
private List<string> GetPDFFiles(string path)
{
string file;
List<string> Pdffilelist = new List<string>();
//Checks whether the given directory exists.
if (Directory.Exists(path))
{
//Gets the list of PDF files located in the directory.
var pdfFiles = Directory.EnumerateFiles(path, "*.pdf", SearchOption.AllDirectories);
foreach (string currentFile in pdfFiles)
{
file = currentFile;
//Adds the file name to the list.
Pdffilelist.Add(file);
}
}
//Returns the list of file names.
return Pdffilelist;
}
|