Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image .Net core在静态文件夹(www)中添加文件夹并保存图像文件_Image_File_Asp.net Core_Directory_Static Files - Fatal编程技术网

Image .Net core在静态文件夹(www)中添加文件夹并保存图像文件

Image .Net core在静态文件夹(www)中添加文件夹并保存图像文件,image,file,asp.net-core,directory,static-files,Image,File,Asp.net Core,Directory,Static Files,在静态文件夹中添加文件,并在静态文件夹中保存图像 在Dot net core项目中保存base64映像。能否给出PathWithFolderName的示例参考:如何将文件保存到磁盘? public class EventMastersController : Controller { private IHostingEnvironment _env; public EventMastersController(IHostingEnvironment env) {

在静态文件夹中添加文件,并在静态文件夹中保存图像


在Dot net core项目中保存base64映像。

能否给出PathWithFolderName的示例参考:如何将文件保存到磁盘?
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");
    }

}