I want to open a PDF file. If I choose PDF Reader, it works fine. If I choose Adobe Reader, I have a message : "letter.pdf already exists. Do you want to replace that file ?"
If I click Yes, it works fine.. And if I click No, it works fine too ! So why do I have this message ?
Here's my code. At first, I tried this
// Access local storage
IStorageFolder local = ApplicationData.Current.LocalFolder;
IStorageFile storageFile = await local.CreateFileAsync("letter.pdf", CreationCollisionOption.ReplaceExisting);
using (Stream stream = await storageFile.OpenStreamForWriteAsync())
{
await stream.WriteAsync(document, 0, document.Length);
}
IStorageFile courrier = await local.GetFileAsync("letter.pdf");
// Launch
var success = await Launcher.LaunchFileAsync(courrier);
If the file already exists, I modified my code to delete it to make sure there is only one file to open.
// Access local storage
IStorageFolder local = ApplicationData.Current.LocalFolder;
if (await local.GetFileAsync("letter.pdf") != null)
{
IStorageFile tmp = await local.GetFileAsync("letter.pdf");
await tmp.DeleteAsync(StorageDeleteOption.PermanentDelete);
}
IStorageFile storageFile = await local.CreateFileAsync("letter.pdf", CreationCollisionOption.ReplaceExisting);
using (Stream stream = await storageFile.OpenStreamForWriteAsync())
{
await stream.WriteAsync(document, 0, document.Length);
}
if (storageFile!= null)
{
var success = await Launcher.LaunchFileAsync(storageFile);
return success;
}
So I have this code, but I still have the message, only with Adobe.. Can anyone explain that ? Thank you very much !
The file is being stored on the phone, not just locally within the app. In order to read it in adobe, it automatically moves a copy into a common folder area.
Because of that, there is already a letters.pdf file there, even if you deleted it from local storage.
You can't (and shouldn't) just assume the user wants to override/delete letters.pdf from their phone, so the pop up needs to stay.
The good news is, whichever option they chose they will still read the file you want them to open