webfrom后台

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LTT_shenpi
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) { }
}
public string GetPictureData(string imagepath, string imgname)
{
//根据图片文件的路径使用文件流打开,并保存为byte[]

DateTime dt = DateTime.Now;

string paths = Server.MapPath("/Image/").ToString();
if (System.IO.Directory.Exists(paths + dt.Year)) //己经存在 年文件夹
{
if (System.IO.Directory.Exists(paths + dt.Year + "/" + dt.Month)) //己经存在 月文件夹
{

}
else
{
System.IO.Directory.CreateDirectory(paths + dt.Year + "/" + dt.Month);
}
}
else
{
System.IO.Directory.CreateDirectory(paths + dt.Year);
if (System.IO.Directory.Exists(paths + dt.Year + "/" + dt.Month)) //己经存在 月文件夹
{

}
else
{
System.IO.Directory.CreateDirectory(paths + dt.Year + "/" + dt.Month);
}
}
// FileStream fs = new FileStream(imagepath, FileMode.Open);

byte[] accessory = Convert.FromBase64String(imagepath);
//byte[] byData = new byte[fs.Length];

System.IO.Stream s = new System.IO.MemoryStream(accessory);
System.Drawing.Image image = System.Drawing.Image.FromStream(s);
string pathstr = Server.MapPath("/Image/" + dt.Year + "/" + dt.Month + "/").ToString() + dt.ToString("yyyyMMddhhmmssfff") + imgname + ".jpg";
// string pathstr = Server.MapPath("/Image/"+ dt.Year + "/" + dt.Month + "/") + dt.ToString("yyyyMMddhhmmssfff") + imgname + ".jpg";
// string pathstr = "d:/Image/" + dt.Year + "/" + dt.Month + "/" + dt.ToString("yyyyMMddhhmmssfff") + imgname + ".jpg";
string sqlpath = "/Image/" + dt.Year + "/" + dt.Month + "/" + dt.ToString("yyyyMMddhhmmssfff") + imgname + ".jpg";
image.Save(pathstr);
return sqlpath;
}
}
}

原文地址:https://www.cnblogs.com/1971855407qq/p/8600237.html