简体   繁体   English

如何从网络服务器将文件保存在 wp7 的应用程序沙箱中?

[英]how to save file in wp7's app sandbox from webserver?

In my application I have to save text file as well as binary files from a webserver by http protocol.在我的应用程序中,我必须通过 http 协议从网络服务器保存文本文件和二进制文件。 Could somebody give me any hints how to proceed?有人可以给我任何提示如何进行吗?

You could download the files and copy them to Isolated Storage.您可以下载文件并将它们复制到独立存储。

Something like this...像这样的东西...

        private void DownloadFiles()
    {
        var wc = new WebClient();
        wc.OpenReadCompleted += WcOpenReadCompleted;
        wc.OpenReadAsync(new Uri("http://myserver/myfile.file", UriKind.Absolute));
    }

    public static void CopyStream(Stream input, Stream output)
    {
        var buffer = new byte[32768];
        while (true)
        {
            int read = input.Read(buffer, 0, buffer.Length);
            if (read <= 0)
                return;

            output.Write(buffer, 0, read);
        }
    }

    private static void WcOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
        {
            var isolatedStorageFileStream = userStoreForApplication.CreateFile("mylocalfilename");

            using (isolatedStorageFileStream)
            {
                CopyStream(e.Result, isolatedStorageFileStream);
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用WP7从网站读取.txt文件? - How can i read a .txt file from a website with WP7? 如何在wp7中管理xml文件中的数据? - how to manage the data in an xml file in wp7? 我尝试使用 WP7 中的隔离存储在 txt 文件中保存许多行,但它只会保存一个,我如何保存很多行? - I try to save many lines in a txt file using isolated storage in WP7 but it will only saves one, how do I save many? 如何在 iOS 中使用 Swift/SwiftUI 将我从应用程序数据导出的文本文件移动到应用程序沙箱之外的位置? - How do I move a text file I exported from app data to a place outside the app's sandbox using Swift/SwiftUI in iOS? 从WP7项目文件夹中的zip文件中读取字节数组 - Read Byte Array from a zip file in project folder in WP7 读取文本文件并添加到列表框WP7 - Read text file and add to Listbox WP7 在网络服务器和本地主机上保存和访问文件 - Save and access file on a webserver and localhost 如何在启用 App Sandbox 的情况下逐行读取文件? - How to read file line by line with App Sandbox enabled? 使用IsolatedStorageFileStream时,保存的文件在WP7中的位置 - Where does the saved file go in WP7 when used IsolatedStorageFileStream 从Web服务器写入文件时出现问题 - Problem writing to a file from webserver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM