在静态文件夹添加文件和文件夹的静态保存图像。
在点网核心项目的base64保存图像。
在静态文件夹添加文件和文件夹的静态保存图像。
在点网核心项目的base64保存图像。
public class EventMastersController : Controller
{
private IHostingEnvironment _env;
public EventMastersController(IHostingEnvironment env)
{
_env = env;
}
public void AddFolderAndImage()
{
var webRoot = _env.WebRootPath;
var PathWithFolderName = System.IO.Path.Combine(webRoot, "MyFolder");
if (!Directory.Exists(PathWithFolderName))
{
// Try to create the directory.
DirectoryInfo di = Directory.CreateDirectory(PathWithFolderName);
string Base64String = eventMaster.BannerImage.Replace("data:image/png;base64,", "");
byte[] bytes = Convert.FromBase64String(Base64String);
Image image;
using (MemoryStream ms = new MemoryStream(bytes))
{
image = Image.FromStream(ms);
}
image.Save(PathWithFolderName + "/ImageName.png");
}
}