I need to open pdf file without store on local storage. i tried this code but i am facing some issues when i am try to read pdf file through PDF Reader, Adobe Reader, etc. after click back navigation i deleted current file from local folder. But after closed my application and I am directly open PDF Reader, Adobe Reader... etc. File is exist(still have on my library). I could not delete the file. Please let me know is possible on windows phone 8 C#.
please see my code below.
Main Functionality is only read the pdf file without saving.
please see my code below.
Code:
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
try
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var fileStream = store.OpenFile("your-file.pdf", FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite))
{
fileStream.Flush();
fileStream.Close();
if (store.FileExists("your-file.pdf"))
{
store.DeleteFile("your-file.pdf");
}
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
await local.DeleteAsync(StorageDeleteOption.PermanentDelete);
}
}
}
catch
{
//File does not exist.
}
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
//RestSharp from Nuget
var client = new RestClient("http://ift.tt/297xE5e;);
var request = new RestRequest("/magazine/file/PDF-2.pdf?c34tP5IxEK=2b26c756615a40844a6564d13a3eb875", Method.GET);
var response = await client.ExecuteTaskAsync(request);
byte[] buffer = response.RawBytes;
using (IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = storageFile.OpenFile("your-file.pdf", FileMode.Create))
{
await stream.WriteAsync(buffer, 0, buffer.Length);
}
}
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile pdffile = await local.GetFileAsync("your-file.pdf");
// Launch the pdf file.
Windows.System.Launcher.LaunchFileAsync(pdffile);
}
from xda-developers http://ift.tt/290uEnj
via IFTTT
No comments:
Post a Comment