Image to base 64 conversion in asp.net

public string ImageToBase64(string ImgUrl)
        {
            string base64ImageRepresentation = "";
            try
            {
                string Imgpath = HttpContext.Current.Server.MapPath("~/AdvertisementImages/") + ImgUrl;
                byte[] imageArray = System.IO.File.ReadAllBytes(Imgpath);

                imageArray = System.IO.File.ReadAllBytes(Imgpath);
                base64ImageRepresentation = Convert.ToBase64String(imageArray);

            }
            catch (Exception ex)
            {
                return base64ImageRepresentation;
            }
            return base64ImageRepresentation;
        }

Comments

Popular posts from this blog

base 64 string To image conversion with compression in asp.net