2014-07-02 73 views
2

更新我的代碼在我的SoundData與var ...線。我實際上只是看到文件夾保存到現在,但我試圖挑選一個文件夾並保存時遇到異常。更改FileSavePicker以將文件從隔離存儲而不是應用程序存儲保存。異常WP8.1

+ $ exception {System.IO.FileNotFoundException:系統找不到指定的文件。

這裏app.xaml.cs:

IStorageFile的SourceFile =等待folder.GetFileAsync(sourceFilePath);

App.xaml.cs:

private async void Application_ContractActivated(object sender, Windows.ApplicationModel.Activation.IActivatedEventArgs e) 
    { 
     var args = e as FileSavePickerContinuationEventArgs; 
     if (args != null) 
     { 
      StorageFile file = args.File; 
      if (file != null) 
      { 
       // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync. 
       CachedFileManager.DeferUpdates(file); 
       // write to file 
       var sourceFilePath = args.ContinuationData["SourceSound"].ToString(); 
       StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation; 
       StorageFile sourceFile = await folder.GetFileAsync(sourceFilePath); 

       IRandomAccessStreamWithContentType sourceStream = await sourceFile.OpenReadAsync(); 

      var bytes = new byte[sourceStream.Size]; 

      var sourceBuffer = await sourceStream.ReadAsync(bytes.AsBuffer(), (uint)sourceStream.Size, Windows.Storage.Streams.InputStreamOptions.None); 

       await FileIO.WriteBufferAsync(file, sourceBuffer); 
       // Let Windows know that we're finished changing the file so the other app can update the remote version of the file. 
       // Completing updates may require Windows to ask for user input. 
       FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file); 
      } 
     } 
    } 

SoundData視圖模型:

private async void ExecuteSaveSoundAs(string soundPath) 
    { 

     var file = await ApplicationData.Current.LocalFolder.GetFileAsync(SavePath); 

     FileSavePicker savePicker = new FileSavePicker(); 
     savePicker.SuggestedSaveFile = file; 
     savePicker.FileTypeChoices.Add("MP3", new List<string>() { ".mp3" }); 
     savePicker.ContinuationData.Add("SourceSound", SavePath); 
     savePicker.SuggestedFileName = this.Title; 
     savePicker.PickSaveFileAndContinue(); 
    } 


    public SoundData() 
    { 
     SaveSoundAs = new RelayCommand<string>(ExecuteSaveSoundAs);    
    } 

SoundModel:

private SoundGroup CreateSoftwareGroup() 
    { 
     SoundGroup data = new SoundGroup(); 

     data.Title = "OS/Software"; 

     data.Items.Add(new SoundData 
     { 
      Title = "Test1", 
      FilePath = "https://xxxxx.test1.mp3", 
      Groups = "Test", 
      SavePath = "Test1.mp3" 
     }); 

     data.Items.Add(new SoundData 
     { 
      Title = "Test2", 
      FilePath = "https://xxxxx.Test2.mp3", 
      Groups = "Test", 
      SavePath = "Test2.mp3" 
     }); 

回答

0

下面是解:

代碼在網主頁。 C S修飾:

var sourceFilePath = args.ContinuationData["SourceSound"].ToString(); 
       StorageFolder folder = ApplicationData.Current.LocalFolder; 
       StorageFile sourceFile = await folder.GetFileAsync(sourceFilePath); 

而且我FileSavePicker代碼:

private async void ExecuteSaveSoundAs(string soundPath) 
    { 

     var file = await ApplicationData.Current.LocalFolder.GetFileAsync(SavePath); 

     FileSavePicker savePicker = new FileSavePicker(); 
     savePicker.SuggestedSaveFile = file; 
     savePicker.FileTypeChoices.Add("MP3", new List<string>() { ".mp3" }); 
     savePicker.ContinuationData.Add("SourceSound", SavePath); 
     savePicker.SuggestedFileName = this.Title; 
     savePicker.PickSaveFileAndContinue(); 
    } 
相關問題