Skip to main content

๐Ÿ‘ฉโ€๐Ÿ’ป ๅœ–็‰‡ๅญ˜ๆช”(base64 to image)

byte[] imageBytes = Convert.FromBase64String(syncImg.StrBase64Img);

using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
{
System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
image.Save(path);
}

ไผบๆœๅ™จๅ–ๅพ—ๆช”ๆกˆ่ทฏๅพ‘่ˆ‡ๅปบ็ซ‹็›ฎ้Œ„โ€‹

        /// <summary>
/// ๅ–ๅพ—ๅœ–็‰‡่ณ‡ๆ–™ๅคพ
/// ่ณ‡ๆ–™ๅคพไธๅญ˜ๅœจๅฐฑๅปบ็ซ‹
/// </summary>
/// <returns></returns>
private string GetFolder()
{
var storagePath = System.Web.Hosting.HostingEnvironment.MapPath("~/"+ type);
if (!System.IO.Directory.Exists(storagePath))
{
System.IO.Directory.CreateDirectory(storagePath);
}
return storagePath;
}

ๅœ–็‰‡่ณ‡่จŠไฟฎๆ”น (ไปปๆ„ๆช”ๆกˆ้€š็”จ)โ€‹

var folder = new DirectoryInfo(storagePath);
IEnumerable<FileInfo> imgList = folder.GetFiles().Where(fi => fi.Name == syncImg.Name);
imgList.First().CreationTime = syncImg.UpdateDateTime; // ๅปบ็ซ‹ๆ™‚้–“
imgList.First().LastWriteTime = syncImg.UpdateDateTime;// ็ทจ่ผฏๆ™‚้–“

ๆฐธไน…ๅˆช้™คๅœ–็‰‡ (ไปปๆ„ๆช”ๆกˆ้€š็”จ)โ€‹

 imgList.Where(fi => fi.Name == del.Key).First().Delete();