Windows phone 8 如果.zip/hpub文件包含.jpg、.woff(web开放字体格式),如何从响应流式写入.zip/epub文件到isolatedStorage

Windows phone 8 如果.zip/hpub文件包含.jpg、.woff(web开放字体格式),如何从响应流式写入.zip/epub文件到isolatedStorage,windows-phone-8,isolatedstorage,epub,sharpziplib,streamwriter.write,Windows Phone 8,Isolatedstorage,Epub,Sharpziplib,Streamwriter.write,实际上,我正试图将一个.zip/.epub文件从webResponse保存到我的wp8独立存储中,该存储包含saveral.html、.png、.jpg和.woff(Web开放字体格式)文件 我下面的代码只保存.zip/.epub中的.html和.png文件,当它尝试保存.jpg和.woff格式文件时,会显示以下异常 异常:不允许对IsolatedStorageFileStream二进制写入程序执行操作 请帮助我解决如何流式编写myFont.woff文件的问题? 我的代码如下 priva

实际上,我正试图将一个.zip/.epub文件从webResponse保存到我的wp8独立存储中,该存储包含saveral.html、.png、.jpg和.woff(Web开放字体格式)文件

我下面的代码只保存.zip/.epub中的.html和.png文件,当它尝试保存.jpg和.woff格式文件时,会显示以下异常

异常:不允许对IsolatedStorageFileStream二进制写入程序执行操作

请帮助我解决如何流式编写myFont.woff文件的问题? 我的代码如下

    private async void ReadWebRequestCallback(IAsyncResult ar)
    {
        IsolatedStorageFile myIsoStorage = IsolatedStorageFile.GetUserStoreForApplication();
        string dir = "/mainDir/subDir/subtosubDir";
        if (!myIsoStorage.DirectoryExists(dir))
        {
            myIsoStorage.CreateDirectory(dir);
        }

        HttpWebRequest myRequest = (HttpWebRequest)ar.AsyncState;
        HttpWebResponse myResponse = (HttpWebResponse)myRequest.EndGetResponse(ar);
        using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
        {
                using (ZipInputStream s = new ZipInputStream(httpwebStreamReader.BaseStream))
                {
                    ZipEntry theEntry;
                    try
                    {
                        while ((theEntry = s.GetNextEntry()) != null)
                        {
                            if (theEntry.IsDirectory) 
                            { 
                                string strNewDirectory = dir+"/"+theEntry.Name; 
                                if (!myIsoStorage.DirectoryExists(strNewDirectory)) 
                                {
                                    myIsoStorage.CreateDirectory(strNewDirectory); 
                                } 
                            }
                           else if (theEntry.IsFile)
                           {
                               string fileName = dir + "/" + theEntry.Name;
                               //save file to isolated storage
                               using (BinaryWriter streamWriter = new BinaryWriter(new IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, myIsoStorage)))
                                {
                                    int size = 2048;
                                    byte[] data = new byte[2048];
                                    while (true)
                                    {
                                        size = s.Read(data, 0, data.Length);
                                        if (size > 0)
                                        {
                                            streamWriter.Write(data, 0, size);
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }

                            }
                        }
                    }
                    catch (Exception ze)
                    {
                        Debug.WriteLine(ze.Message);
                    }
                }

        }
    }
在我的例子中,这是将不同扩展名的文件保存到独立存储中的唯一方法,BinaryWriter将无法工作。所以@KooKiz是对的


谢谢Kookiz:)

这不会解决您的问题,但请不要直接使用
CopyTo
方法将流复制到另一个流中。因此,只需创建IsolatedStorageFileStream,您就可以直接使用
s.CopyTo(您的IsolatedStorageFileStream)
,跳过二进制编写器altogetherhi@KooKiz,感谢您的关注,我无法正确获取您的建议,请探索您的建议。谢谢。@KooKiz我已经成功地完成了这个任务,我已经在底部写了三行我的答案。
using (IsolatedStorageFileStream fileStream = isf.OpenFile(fullFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
     s.CopyTo(fileStream);
}