簡體   English   中英

如何將圖像從http服務器存儲到本地文件夾? C#(Win8,應用程序)

[英]How to store an image from http server to local folder? c# (win8, app)

我想將圖像存儲到從http服務器接收的本地文件夾中。

該請求(http:// myServer:myPort /?imageID = 5)傳遞了一個“ tif-image-file”。 如果我將此請求輸入Internet-Explorer,則可以使用!

我的C#代碼:

(...)
Uri myUri = new Uri("http://myServer:myPort/?imageID=5");
StorageFile myFile = StorageFile.GetFileFromApplicationUriAsync(myUri);
(...)

但是“ myFile”始終為null :(

我做錯了什么?

謝謝!

看不見的

好的,這是我的解決方案:

  1. 我在文件夾中創建了一個空文件

      string myFilename = "myfile.tif"; StorageFile myFile = await myFolder.CreateFileAsync(myFilename, CreationCollisionOption.ReplaceExisting); 
  2. 后台下載器

      try { var download = new BackgroundDownloader().CreateDownload(myUri, myFile); await download.StartAsync(); } catch (Exception E) { ... } 

下一個問題是,僅當我每次將“發布模式”從“ X64”更改為“ AnyCPU”,反之亦然時,它才起作用。 如果我不更改發布模式,則我的應用程序什么也不做。 沒有異常,沒有程序崩潰...

這是錯誤嗎?

(對不起,我的英語不好...)

計划將GetFileFromApplicationUriAsync方法用於加載本地應用程序資源。 因此,它不適合您的情況。 您需要使用CreateStreamedFileAsnyc方法創建一個新的Storage文件:
http://msdn.microsoft.com/zh-CN/library/windows/apps/windows.storage.storagefile.createstreamedfileasync.aspx

編輯:在您的情況下,使用CreateStreamedFileFromUriAsync()會更容易: http : //msdn.microsoft.com/zh-cn/library/windows/apps/windows.storage.storagefile.createstreamedfilefromuriasync.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM