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

    反思 空杯 担当
  • 相关阅读:
    Oracle数据库的dual表的作用
    数据库中CASE函数和Oracle的DECODE函数的用法
    Oracle数据库中,通过function的方式建立自增字段
    Java学习(十三):抽象类和接口的区别,各自的优缺点
    Java学习(十八):二叉树的三种递归遍历
    Sublime工具插件安装
    sizeof和strlen
    I2C接口的EEPROM操作
    关于窗口看门狗
    关于指针传入函数
  • 原文地址:https://www.cnblogs.com/oralig/p/9856689.html
Copyright © 2011-2022 走看看