IEnumerable to Stream for FileStreamResult

前端 未结 2 1615
梦毁少年i
梦毁少年i 2021-01-14 08:38

I have an IEnumerable, which is \"streamed\" per yield statements from a method. Now I want to convert this enumerable to a Str

2条回答
  •  半阙折子戏
    2021-01-14 09:00

    I think you can use it in this first convert your string to byte array and use memory stram afterwards

    string sourceFile = System.Web.HttpContext.Current.Server.MapPath(Path.Combine("/", "yourAddress"));
    byte[] byteArray = System.IO.File.ReadAllBytes(sourceFile);
    
    MemoryStream mem;
            using (mem = new MemoryStream())
            {
                mem.Write(byteArray, 0, (int)byteArray.Length);
                return mem;
            }
    

提交回复
热议问题