Rename File in IsolatedStorage

前端 未结 3 1752
闹比i
闹比i 2021-01-05 03:32

I need to rename a file in the IsolatedStorage. How can I do that?

相关标签:
3条回答
  • 2021-01-05 03:57

    Perfectly execute this piece of code

    string oldName="oldName";
    string newName="newName";
    var file = await ApplicationData.Current.LocalFolder.GetFileAsync(oldName);
    await file.RenameAsync(newName);
    
    0 讨论(0)
  • 2021-01-05 04:03

    In addition to the copy to a new file, then delete the old file method, starting with Silverlight 4 and .NET Framework v4, IsolatedStorageFile exposes MoveFile and MoveDirectory methods.

    0 讨论(0)
  • 2021-01-05 04:21

    There doesn't appear to anyway in native C# to do it (there might be in native Win32, but I don't know).

    What you could do is open the existing file and copy it to a new file and delete the old one. It would be slow compared to a move, but it might be only way.

    var oldName = "file.old"; var newName = "file.new";
    
    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
    using (var readStream = new IsolatedStorageFileStream(oldName, FileMode.Open, store))
    using (var writeStream = new IsolatedStorageFileStream(newName, FileMode.Create, store))
    using (var reader = new StreamReader(readStream))
    using (var writer = new StreamWriter(writeStream))
    {
      writer.Write(reader.ReadToEnd());
    }
    
    0 讨论(0)
提交回复
热议问题