简体   繁体   English

在隔离存储wp7中创建文件

[英]creating a file in isolated storage wp7

I am using following code to create a file in isolated storage 我正在使用以下代码在隔离存储中创建文件

mystorage = IsolatedStorageFile.GetUserStoreForApplication();
if (mystorage.FileExists(scanName))
{
    mystorage.DeleteFile(scanName);
}
WriteableBitmap wb = new WriteableBitmap(canImage, null);
using (MemoryStream stream = new MemoryStream())
{
    wb.SaveJpeg(stream, (int)canImage.Width, (int)canImage.Height, 0, 100);
    using (IsolatedStorageFileStream local = new IsolatedStorageFileStream(scanName, FileMode.Create, mystorage))
    {
        local.Write(stream.GetBuffer(), 0, stream.GetBuffer().Length);
    }
}
if (MessageBox.Show("Scan updated successfully") == MessageBoxResult.OK)
{
    App.isTransformRequest = false;
    NavigationService.Navigate(new Uri("/View/EditDocument.xaml?paramList=" + App.currentName, UriKind.RelativeOrAbsolute));
}

this code works fine. 此代码可以正常工作。 But I want to detect weather the file is completely created or not, and after that only I want to display the success message. 但是我想检测天气是否完全创建了文件,此后,我只想显示成功消息。 The way I am currently working somtimes displays the success message before the complete creation of the file, I want the message to be displayed only after the file is created completely, ie the stream is written completely. 我当前的工作方式是在完全创建文件之前显示成功消息,我希望仅在文件完全创建(即流已完全写入)之后显示该消息。

Using the BeginWrite Method of the IsolatedStorageFileStream (msdn) you can regsiter a ActionCallback to continue with the redirection options in your UI. 使用IsolatedStorageFileStream (msdn)BeginWrite方法,您可以在ActionCallback上重新注册以继续使用UI中的重定向选项。

Please note, if your callback shows a MessageBox in the UI-Thread, you have to sync the ThreadContext using the Dispatcher (msdn) 请注意,如果您的回调在UI-Thread中显示MessageBox,则必须使用Dispatcher (msdn)同步ThreadContext。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM