从本地存储复制Sqlite文件到WP8.1中的SD卡

问题描述:

如何将我的文件从本地存储复制到WP8.1中的sd卡或已知文件夹用于备份目的?从本地存储复制Sqlite文件到WP8.1中的SD卡

我正在使用文件夹选取器来选择保存位置。

我的代码是:

Private Async Sub ButtonBackup_Click(sender As Object, e As RoutedEventArgs) 
    Dim FolderPicker As New FolderPicker() 
    FolderPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary 

    FolderPicker.ViewMode = PickerViewMode.List 
    FolderPicker.PickFolderAndContinue() 

End Sub 

Public Async Sub ContinueFolderPicker(ByVal args As FolderPickerContinuationEventArgs) Implements IFolderPickerContinuable.ContinueFolderPicker 
    Dim folder As StorageFolder = args.Folder 
    If folder IsNot Nothing Then 
     ' Application now has read/write access to all contents in the picked folder (including other sub-folder contents) 
     StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder) 
     'OutputTextBlock.Text = "Picked folder: " & folder.Name 
    Else 
     'OutputTextBlock.Text = "Operation cancelled." 
    End If 
    Dim file As StorageFile = Await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("ContactsManager.sqlite") 
    CopyFileToFolder(file, folder) 

End Sub 

Public Async Sub CopyFileToFolder(ByVal filetoCopy As StorageFile, ByVal folder As StorageFolder) 
    Await filetoCopy.CopyAsync(folder) 
End Sub 

但低于行不启动:

Public Async Sub ContinueFolderPicker(ByVal args As FolderPickerContinuationEventArgs) Implements IFolderPickerContinuable.ContinueFolderPicker 

最后我解决我的问题,下面的代码是corrent。

Private Async Sub ButtonBackup_Click(sender As Object, e As RoutedEventArgs) 
    Dim SqliteStorageFile As StorageFile = Await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("ContactsManager.sqlite") 

    Dim buffer() As Byte 
    Dim stream As Stream = Await SqliteStorageFile.OpenStreamForReadAsync() 
    buffer = New Byte(stream.Length - 1) {} 
    Await stream.ReadAsync(buffer, 0, CInt(stream.Length)) 

    Dim savePicker = New FileSavePicker() 
    savePicker.FileTypeChoices.Add("Backup File", New List(Of String)() From {".backup"}) 
    savePicker.SuggestedFileName = SqliteStorageFile.Name 

    Dim file = Await savePicker.PickSaveFileAsync() 
    If file IsNot Nothing Then 
     CachedFileManager.DeferUpdates(file) 
     Await FileIO.WriteBytesAsync(file, buffer) 
     CachedFileManager.CompleteUpdatesAsync(file) 
    End If 
End Sub