Csharp/C#教程:如何使用c#将byte 转换为HttpPostedFileBase分享


如何使用c#将byte 转换为HttpPostedFileBase

如何使用c#将byte []转换为HttpPostedFileBase。 在这里,我尝试了以下方式。

byte[] bytes = System.IO.File.ReadAllBytes(localPath); HttpPostedFileBase objFile = (HttpPostedFileBase)bytes; 

我得到一个不能隐式转换错误。

如何创建自定义的发布文件? ?

 public class MemoryPostedFile : HttpPostedFileBase { private readonly byte[] fileBytes; public MemoryPostedFile(byte[] fileBytes, string fileName = null) { this.fileBytes = fileBytes; this.FileName = fileName; this.InputStream = new MemoryStream(fileBytes); } public override int ContentLength => fileBytes.Length; public override string FileName { get; } public override Stream InputStream { get; } } 

你可以这样使用:

上述就是C#学习教程:如何使用c#将byte 转换为HttpPostedFileBase分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 byte[] bytes = System.IO.File.ReadAllBytes(localPath); HttpPostedFileBase objFile = (HttpPostedFileBase)new MemoryPostedFile(bytes); 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/955693.html

(0)
上一篇 2021年11月21日
下一篇 2021年11月21日

精彩推荐