This function is working for images, but i'm stucked at the point to use it for pdf, audio and video also. I am receiving data in base64 format in asp.net web API and have to save it in folders and file name in database.
public static String LoadBase64(string base64File) { try { if (!string.IsNullOrEmpty(base64File)) { String path = HttpContext.Current.Server.MapPath("~/Images"); var fileName = DateTime.Now.ToFileTime() + ".jpg"; string imgPath = Path.Combine(path, fileName); byte[] imageBytes = Convert.FromBase64String(base64File); MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length); ms.Write(imageBytes, 0, imageBytes.Length); System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true); image.Save(imgPath, System.Drawing.Imaging.ImageFormat.Jpeg); return fileName; } else { return "Null"; } } catch (Exception ex) { return (ex.Message); } }