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

    反思 空杯 担当
  • 相关阅读:
    maven .assembly
    命令参数解析库JCommonder
    OWL,以及XML,RDF
    Ambari是什么?
    上海新桥>风景服务区>宁波江东区车管所 及返程路线
    武汉旅游地图(zz)
    武汉旅游(zz)
    上海市松江区 <> 上海市金山区枫泾·万枫东路ab6177,racehttp://live.racingchina.com/
    明中路明华路到第九人民医院路线
    月台路春申塘桥到虹桥火车站
  • 原文地址:https://www.cnblogs.com/oralig/p/9856689.html
Copyright © 2011-2022 走看看