现在的问题就是我拖出一个button和fileupload控件 要求上传到指定的地址中并以上传时间创建一个新的文件夹  这个怎么实现

解决方案 »

  1.   


    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.IO;public partial class Default3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = FileUpload1.FileName;
            string type = FileUpload1.FileName.Substring(name.LastIndexOf(".") + 1).ToLower();       
            DirectoryInfo dir = new DirectoryInfo(Server.MapPath("img"));
            string upLoadTime = System.DateTime.Now.ToString("yyyyMMHHmmss");
            dir.CreateSubdirectory(upLoadTime);
            string ipath = Server.MapPath("img")+"\\"+upLoadTime + "\\"+name;
            string wpath = "img" + "\\"+upLoadTime+ "\\" + name;        if (type == "jpg" || type == "gif" || type == "bmp" || type == "png")
            {            FileUpload1.SaveAs(ipath);
                Image1.Visible = true;
                Image1.ImageUrl = wpath;
               
            }
            else
            {
               //
            }
        }
    }
      

  2.   

    揭贴率应该不是结贴率吧,揭贴率应该是回贴子的比率吧和普通的上传是一样的,读取数据流,然后保存就行了  接收fileupload1.postedfile.inputstream,然后,io.file.save
      

  3.   

     protected void Button2_Click(object sender, EventArgs e)
        {        if (fulpicsmall.FileName == "")
            {
                ClientScript.RegisterStartupScript(typeof(string), "notnull", "<script>alert('请选择要上传的图')</script>");
                fulpicsmall.Focus();
                return;
            }       string expicName="jpg,img,gif,pci,bmp,pdf";//允许上传的图片的扩展名
            string[] strarray=expicName.Split(',');//把expicname的字符串以逗号(,)分隔,放到数组中
            string picstr=fulpicsmall.PostedFile.FileName;//要上传的文件全路径
            string filename = picstr.Substring(picstr.LastIndexOf("\\") + 1);//原文件名,包括扩展名
            string exfileName = picstr.Substring(picstr.LastIndexOf("."));//获取文件的扩展名,例如(.jpg)
            string exfileNamepot=exfileName.Substring(1).ToLower();//获得exfileName字符串中从1开始到结束的字符串(获得扩展名除“.”的字符)
            int picrange = fulpicsmall.PostedFile.ContentLength / 1024; //上传的文件大小(kb)        if (picrange > 6300)
            {
                ClientScript.RegisterStartupScript(typeof(string), "morethan5m", "<script>alert('文件超过5M,不适合网络浏览')</script>");
            }        else
            {//判断扩展名是否合法
                bool IsNo = false;
                foreach (string k in strarray)
                {
                    if (exfileNamepot.ToString().Trim() == k.ToString().Trim())
                    {                    IsNo = true;//如果是合法扩展名的图片,则IsNo为true;否则为false;  
                        break;
                    }
                }
                if (!(bool)IsNo)
                {//如果不是合法图片的扩展名
                    ClientScript.RegisterStartupScript(typeof(string), "notfit", "<script>alert('图片格式不合法')</script>");
                }            else
                {//如果是合法图片格式                string fnewName = System.DateTime.Now.ToString("yyyyMMHHmmss");//新的时间为文件名(无扩展名)
                   string fallName = fnewName + exfileName;//新的文件名(包含扩展名)
                    string path = Server.MapPath("productspic\\");//文件夹new_pic的物理路径
                    path += fallName;//上传后的文件物理路径   
                    fulpicsmall.PostedFile.SaveAs(path);//将要上传的文件保存到指定的路径下和文件名,path为物理路径
                    ViewState["productspicsmall"] = "productspic/" + fallName;//要保存到数据库里的文件路径
                    this.Image1.ImageUrl = (string)ViewState["productspicsmall"];//将页面图片显示为刚上传的图片
                }
            }    }