Reputation: 1347
In my app, I send an email with Windows Store Share Contract. Everything works fine, only one problem what I cant solve. Where and how can I delete the created file? Because if I delete it anywhere, the email goes without attachment. There is my code:
async void ShareImageHandler(DataTransferManager sende, DataRequestedEventArgs e)
{
DataRequest request = e.Request;
DataRequestDeferral deferral = request.GetDeferral();
var localFolder = ApplicationData.Current.LocalFolder;
var file = await localFolder.CreateFileAsync(Guid.NewGuid(); + ".png");
var screenShotter = new ScreenShotter();
try
{
await screenShotter.SaveVisualElementToFileAsync(
gridPrintForPostCard, file, new Rect(0, 0, 10000, 10000));
request.Data.Properties.Thumbnail =
RandomAccessStreamReference.CreateFromFile(file);
request.Data.SetBitmap(
RandomAccessStreamReference.CreateFromFile(file));
}
finally
{
deferral.Complete();
}
}
Upvotes: 1
Views: 73
Reputation: 116636
You can add a background task that runs even when the app isn't running that periodically clears away the temporary files. You can even have conditions on when it can run, like if the user is away from the computer for example. More Info: Guidelines for background tasks
A more simple solution would be to simply delete all of them when you app starts (loaded event) or shuts down. But it's a less robust solution.
Upvotes: 2