1.在你使用FreeTextBox 的那个页面的后台添加一个函数如下:如default.aspx.cs
public string GetPath()
{
string path = "../eppwt/upfiles/images/"; //事先创建的虚拟目录
DateTime now = DateTime.Now; // 定义时间变量并赋值为当前时间
string year = now.Year.ToString().Trim();// 获取当前时间的年份,下同
string month = now.Month.ToString().Trim();
string day = now.Day.ToString().Trim();
string hour = now.Hour.ToString().Trim();
string filepath = path + year + "_" + month + "/" + day;// 获取括号内的虚拟路径对应的物理路径
if (!System.IO.Directory.Exists(Server.MapPath(filepath)))
System.IO.Directory.CreateDirectory(Server.MapPath(filepath));
return filepath;
}
2.在default.aspx.cs的Page_Load事件中。添加如下代码:
this.FreeTextBox1.ImageGalleryPath = GetPath();
3.运行........成功!
public string GetPath()
{
string path = "../eppwt/upfiles/images/"; //事先创建的虚拟目录
DateTime now = DateTime.Now; // 定义时间变量并赋值为当前时间
string year = now.Year.ToString().Trim();// 获取当前时间的年份,下同
string month = now.Month.ToString().Trim();
string day = now.Day.ToString().Trim();
string hour = now.Hour.ToString().Trim();
string filepath = path + year + "_" + month + "/" + day;// 获取括号内的虚拟路径对应的物理路径
if (!System.IO.Directory.Exists(Server.MapPath(filepath)))
System.IO.Directory.CreateDirectory(Server.MapPath(filepath));
return filepath;
}
意思是以年月日来命名文件夹。
或者根据用户名创建用户个人的图片库,避免多用户的图片混用,同时保护隐私,只需把上面定义的时间作为子路径换做用户名即可。一种方法是调用登陆后的用户名的Session。
例如:hostpath=Session["userid"].Tostring();
最后将 string filepath=path+“_”+hostpath;
其他的代码同上文,
2.在default.aspx.cs的Page_Load事件中。添加如下代码:
this.FreeTextBox1.ImageGalleryPath = GetPath();
3.运行........成功!
浙公网安备 33010602011771号