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

    反思 空杯 担当
  • 相关阅读:
    vue-生命周期图示 注解
    vue-组件嵌套之——父组件向子组件传值
    vue-框架模板的源代码注释
    vue-小demo、小效果 合集(更新中...)
    Gulp-自动化编译sass和pug文件
    JS
    Node.js- sublime搭建node的编译环境
    sublime--package control的配置与插件安装
    git-常用命令一览表
    java面试题:jvm
  • 原文地址:https://www.cnblogs.com/oralig/p/9856689.html
Copyright © 2011-2022 走看看