locked
Load File from SDCard in EpubReader RRS feed

  • Question


  •       I integrated (this)EPUB Reader reader to my project. It is working fine. & I want to load the file from SDCard instead of Isolated storage of device

    To open file from Isolated storage we have IsolatedStorageFileStream like this

    IsolatedStorageFileStream isfs;    
    using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())    
         {
            try        
            { 
               isfs = isf.OpenFile([Path to file], FileMode.Open); 
            }
            catch        
            { 
               return; 
            }    
        }
        EPubViewer.Source = isfs;

     For file in SDcard I tried like this

    ExternalStorageDevice sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();                   
     // If the SD card is present, get the route from the SD card.      
        if (sdCard != null)         {                        ExternalStorageFile file = await sdCard.GetFileAsync(_sdFilePath);                        // _sdFilePath is string that having file path of file in SDCard                            // Create a stream for the route.                        Stream file = await file.OpenForReadAsync();                   
    // Read the data.                          ePubView.Source = file;                  }

    Error

    If You want try.. Here is my project sample link

    Question : How can I give my file as source epubView control
    Is this is proper way, please give a suggestion regarding this..
    Thanks

    devendra





    • Edited by GDEVENDRAK Tuesday, January 28, 2014 1:38 PM
    Tuesday, January 28, 2014 1:23 PM

Answers

  • Try this:

    ExternalStorageFile file = await sdCard.GetFileAsync(_sdFilePath);
    Stream s = await file.OpenForReadAsync();
    MemoryStream memoryStream = new MemoryStream((int)s.Length);
    await s.CopyToAsync(memoryStream);
    ePubView.Source = memoryStream.AsInputStream().AsStreamForRead();

    • Marked as answer by GDEVENDRAK Thursday, January 30, 2014 12:56 PM
    Tuesday, January 28, 2014 3:07 PM

All replies