小编Dan*_*iel的帖子

如何在c#中使用UWP下载文件

我是编程的初学者,我想知道在UWP中下载文件的正确方法我现在使用它,但它只能在50%的时间内工作:

public async Task StartDownload()
{
    try
    {
        StorageFile sf = await DownloadsFolder.CreateFileAsync(title.Text, CreationCollisionOption.GenerateUniqueName);
        downloadFolder = (await sf.GetParentAsync()).ToString();
        HttpClient client = new HttpClient();
        byte[] buffer = await client.GetByteArrayAsync(inputURL);
        using (Stream stream = await sf.OpenStreamForWriteAsync())
        {
            stream.Write(buffer, 0, buffer.Length);
        }
        path = sf.Path;
    }
    catch (Exception e)
    {
        MessageDialog dialog = new MessageDialog("Sorry, something went wrong...", "An error...");
        await dialog.ShowAsync();
    }
}
Run Code Online (Sandbox Code Playgroud)

例外情况是:"0x750F6D7E处的未处理异常(program.exe 0xC000027B中的combase.dll;发生了应用程序内部异常(参数:0x16E73128,0x00000001)."

提前致谢

c# uwp

3
推荐指数
1
解决办法
6432
查看次数

标签 统计

c# ×1

uwp ×1