隔离存储-在Windows Phone中复制html文件时不允许操作

本文关键字:文件 html 不允许 操作 复制 存储 Windows Phone 隔离 | 更新日期: 2023-09-27 18:03:27

当我运行

IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
myStore.CopyTextFile("HTDocs''help.html", true);

我有错误:"操作不允许在IsolatedStorageFileStream "。这是教程里的。我该如何解决这个问题?

public static class ISExtensions
    {
        public static void CopyTextFile(this IsolatedStorageFile isf, string filename, bool replace = false)
        {
            if (!isf.FileExists(filename) || replace == true)
            {
                StreamReader stream = new StreamReader(TitleContainer.OpenStream(filename));
                IsolatedStorageFileStream outFile = isf.CreateFile(filename);
                //
                //
                string fileAsString = stream.ReadToEnd();
                byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(fileAsString);
                outFile.Write(fileBytes, 0, fileBytes.Length);
                stream.Close();
                outFile.Close();
            }
        }
}

隔离存储-在Windows Phone中复制html文件时不允许操作

试试这样:

// isolated storage
IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
// access to resource files
StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri(@"HTDocs'help.html", UriKind.Relative));
using (Stream origFileStream = streamInfo.Stream)
{
    // open the filestream for the isostorage file and copy the content from the original stream
    using (IsolatedStorageFileStream fileStream = myStore.CreateFile("help.html"))
    {
        origFileStream.CopyTo(fileStream);
        origFileStream.Close();
    }
}