高手们来个文件上传的代码吧,急用啊!!!!

解决方案 »

  1.   

    if(btnFile.PostedFile.ContentLength < 1)
    {
    Response.Write(Utils.AlertMessage("请选择要上传的文件!"));
    return;
    }
    string strFiltrate = btnFile.PostedFile.FileName;
    strFiltrate = System.IO.Path.GetExtension(strFiltrate);
    if(strFiltrate!=".doc" && strFiltrate !=".xls")
    {
    Response.Write(Utils.AlertMessage("上传的文件类型只能是WORD或者EXCEL"));
    return;
    }
    //如果该文件夹不存在,则创建
    if(System.IO.Directory.Exists(Server.MapPath(FILE_UP_URL))==false)
    {
    System.IO.Directory.CreateDirectory(Server.MapPath(FILE_UP_URL));
    } string fileType = System.IO.Path.GetExtension(btnFile.PostedFile.FileName);
    string filePath = btnFile.PostedFile.FileName; //获取文件绝对路径
    string oldName = filePath.Substring(filePath.LastIndexOf("\\")+1); //从文件绝对路径字符串中,取到文件名称
    int fileSize = btnFile.PostedFile.ContentLength; //取得文件大小

    string strxxlsh=Utils.GetRandom(1000,9999);
    string newName = DateTime.Now.ToString("yyyyMMddHHmmssff") + fileType;
    /*
    *Insert to table
    */