中文
    razor C#把文件转Base64字符串
    2019-06-09 10:19:34 分享 举报
    内容简介:razor C#把文件转Base64字符串
    作者:达人设计 LV.1 浏览(12943) 喜欢(0) 评论(0)

    @functions{

        public static string Base64String(string url)

        {

            try{

                var location = Server.MapPath(url);

                System.IO.FileStream file = System.IO.File.OpenRead(location);

                System.IO.BinaryReader Binary = new BinaryReader(file);

                byte[] bytes = Binary.ReadBytes(Convert.ToInt32(file.Length));

                string base64String = Convert.ToBase64String(bytes);

                return base64String;

            }

            catch{

                return "";

            }

        }

    }

    输出

    <video controls="controls" autoplay="autoplay" style="width:1200px;"><source src="data:video/mp4;base64,@razor.Base64String(url)"  type="video/mp4"></video>

    •  
    上一页 1 下一页
     点击图片添加 X
     点击图片添加 X