Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将图像从http服务器存储到本地文件夹?c#(win8,应用程序)_C#_Http_Directory_Store - Fatal编程技术网

如何将图像从http服务器存储到本地文件夹?c#(win8,应用程序)

如何将图像从http服务器存储到本地文件夹?c#(win8,应用程序),c#,http,directory,store,C#,Http,Directory,Store,我想将一个图像存储到一个本地文件夹中,该文件夹是从http服务器接收的 请求(http://myServer:myPort/?imageID=5)提供一个“tif图像文件”。如果我在Internet Explorer中输入此请求,它会工作 我的c代码: 但“myFile”始终为空:( 我做错了什么 谢谢 不可见地将GetFileFromApplicationUriAsync方法用于加载本地应用程序资源。因此它不适合您的情况。您需要使用CreateStreamedFileLeasnyc方法创建一个

我想将一个图像存储到一个本地文件夹中,该文件夹是从http服务器接收的

请求(http://myServer:myPort/?imageID=5)提供一个“tif图像文件”。如果我在Internet Explorer中输入此请求,它会工作

我的c代码:

但“myFile”始终为空:(

我做错了什么

谢谢


不可见地

GetFileFromApplicationUriAsync
方法用于加载本地应用程序资源。因此它不适合您的情况。您需要使用
CreateStreamedFileLeasnyc
方法创建一个新的
存储
文件:


编辑:在您的情况下,使用
CreateStreamedFileFromUriAsync()

好的,这是我的解决方案:

  • 我在文件夹中创建了一个空文件

     string myFilename = "myfile.tif";
     StorageFile myFile = await myFolder.CreateFileAsync(myFilename, CreationCollisionOption.ReplaceExisting);
    
  • 背景下载程序

     try
     {
         var download = new BackgroundDownloader().CreateDownload(myUri, myFile);
         await download.StartAsync();
     }
     catch (Exception E)
     {
         ...
     }
    
  • 下一个问题是,只有我每次都将发布模式从“X64”更改为“AnyCPU”,反之亦然,它才起作用。如果我不更改发布模式,我的应用程序什么也不做。没有异常,没有程序崩溃

    这是虫子吗


    (很抱歉我的英语不好…

    谢谢,这样可以,但下一个问题是,我无法保存存储文件“myFile”…StorageFolder folder=KnownFolders。(……;string filename=“image.tif”;Wait myFile.CopySync(文件夹,文件名);没有异常,应用程序只是停止…你有没有碰巧发现这个错误?CreateStreamdFileFromUriAsync检索该文件,但我在尝试从该流文件到存储文件执行CopySync时遇到异常“系统找不到指定的文件。(HRESULT中的异常:0x80070002)”。有什么想法吗?
     try
     {
         var download = new BackgroundDownloader().CreateDownload(myUri, myFile);
         await download.StartAsync();
     }
     catch (Exception E)
     {
         ...
     }