zoukankan      html  css  js  c++  java
  • 文件上传-获取上传文件路径

    #region 文件上传-获取上传文件路径
    public string FilePath()
    {
    DataTable dtStu = s1.select(" select * from Student_V where tblstudentid = " + studentID + "");
    string userName = "";
    if (dtStu.Rows.Count > 0)
    {
    userName = dtStu.Rows[0]["name"].ToString();
    }
    System.Web.HttpFileCollection _file = System.Web.HttpContext.Current.Request.Files;
    string path = "";
    //if (_file.Count > 0)
    if (_file[0].ContentLength > 0)
    {
    long size = _file[0].ContentLength;
    string type = _file[0].ContentType;
    string name = _file[0].FileName;
    string _tp = System.IO.Path.GetExtension(name);
    if (_tp.ToLower() == ".docx")
    {
    System.IO.Stream stream = _file[0].InputStream;
    string saveName = userName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + _tp;
    int length = (int)stream.Length;
    BinaryReader br = new BinaryReader(stream);
    FileStream fs;
    path = System.Web.HttpContext.Current.Server.MapPath(@"~/UpLoadFile/Student/" + saveName);
    //string path = @"../UpLoadFile/Tutors/" + saveName;
    fs = File.Create(path);
    fs.Write(br.ReadBytes(length), 0, length);
    br.Close();
    fs.Close();
    //保存数据表中的路径
    path = @"../UpLoadFile/Student/" + saveName;
    }
    else
    {
    ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请选择文件类型为.docx的文件');window.location.href=window.location.href;window.close();", true);
    }
    }
    else
    {
    ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请选择文件');window.location.href=window.location.href;window.close();", true);
    }

    return path;
    }
    #endregion

    反思 空杯 担当
  • 相关阅读:
    Java并发之Thread类的使用
    剑指Offer
    总结下2017之前的几年
    解决一个特定的负载均衡下定时任务执行多次的问题
    《MYSQL》----字符串的复杂函数,检索的七-天-排-重
    科学计数法的转换
    小伙伴自言自语发给我的聊天记录,一句都看不懂
    记录下一个让我调了一天的失误
    记录一个从没见过的bug
    吐槽下
  • 原文地址:https://www.cnblogs.com/oralig/p/9856689.html
Copyright © 2011-2022 走看看