示例#1
0
        public async Task <StorageFile> GetFileAsync()
        {
            try
            {
                var httpClient = new Windows.Web.Http.HttpClient();
                var buffer     = await httpClient.GetBufferAsync(new Uri("http://www.neu.edu.cn/indexsource/neusong.mp3"));

                if (buffer != null)
                {
                    StorageFile File = await KnownFolders.MusicLibrary.CreateFileAsync(
                        "neusong.mp3", CreationCollisionOption.ReplaceExisting);

                    using (var stream = await File.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        await stream.WriteAsync(buffer);

                        await stream.FlushAsync();
                    }
                    //  var stream = await File.OpenAsync(FileAccessMode.ReadWrite);
                    // await stream.WriteAsync(buffer);
                    //await stream.FlushAsync();
                    MyText.Text = "neusong";
                    return(File);
                }
            }
            catch { }
            return(null);
        }