亚洲精品亚洲人成在线观看麻豆,在线欧美视频一区,亚洲国产精品一区二区动图,色综合久久丁香婷婷

              當前位置:首頁 > IT技術 > Windows編程 > 正文

              c#項目返回文件案例
              2021-10-28 15:25:09

              C#項目API返回文件案例

                             string path = "你的文件地址/測試文件.txt";
                              var filestream = new FileStream(path, FileMode.OpenOrCreate);
                              HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
                              response.Content = new StreamContent(filestream);
                              response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                              response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")  { FileName = "測試文件.txt" }; 
                            return response;
              

              MVC項目返回文件案例

              string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                byte[] fileContents="文件轉化后的byte";
                return File(outfile, $"{fileContents};Charset=utf-8", $"行政費用申請{DateTime.Now.ToString("yyyy-MM-dd")}.xlsx");

              本文摘自 :https://www.cnblogs.com/

              開通會員,享受整站包年服務立即開通 >