簡體   English   中英

ASP.NET,Webservice 響應作為 Android 的下載鏈接

[英]ASP.NET, Webservice response as a download link for Android

因為這個網絡服務應該使用android 設備來使用,根據我朋友告訴我的,他說他唯一的方法就是下載一個文件並從那里讀取

這個項目沒有上線,它在一台電腦上演示。 因此,該文件可以保存在 C:\ 文件夾中,而不是實時服務器中。

所以現在我正在嘗試找到一種方法來返回下載文件鏈接,而不是原來的 XML 格式。 我正在尋找的下載鏈接格式是.xml

我的 web 服務采用以下格式:

我有 Location.cs

public List<Locations> ws(string parameter)
{
List<Locations> abc = new List<Locations>();
// Over here I populate the abc list with objects.
return abc;
}

至於 ASp.NET 和 C# 部分,你可以做這樣的事情。

每當您有文件數據時,都應將其寫入文件。 而不僅僅是調用這個 function 傳遞路徑和文件名,你想出現在另一端。

//Forces Download/Save rather than opening in Browser//
  public static void ForceDownload(string virtualPath, string fileName)
  { 

    Response.Clear();
    Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
    Response.WriteFile(virtualPath);
    Response.ContentType = "";
    Response.End(); 

  } 

暫無
暫無

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

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