zoukankan      html  css  js  c++  java
  • 文件的上传

    这些是主要的代码

    文件上传的

    protected void 学生上传信息_upfile_Click(object sender, EventArgs e)//文件上传
        {
            学生上传信息.Text = upfile(学生上传信息_file, MapPath("..") + "/uploadfile/", "uploadfile/");
            教师下载信息.Text = 学生上传信息.Text;
        }

    protected string upfile(FileUpload fp, string jfathhead, string xfathhead)
        {
            if (!fp.HasFile) { Response.Write("<script>alert('请选择文件!');</script>"); return "0"; }
            else
            {
                int index1 = fp.FileName.LastIndexOf(".") + 1;
                int index2 = fp.FileName.Length - index1;
                string lx = fp.FileName.Substring(index1, index2);//取文件类型
                // string time = System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString()
                //       + System.DateTime.Now.Second.ToString() + System.DateTime.Now.Millisecond.ToString();
                //以时间作为文件ID,精确到微秒;
                string fileName = fp.PostedFile.FileName.Substring(fp.PostedFile.FileName.LastIndexOf("\\") + 1);


                string fullpath = jfathhead +学号.Text+姓名.Text+ 课程名称.Text +上传时间.Text+ "." + lx;//服务器文件绝对路径;
                string path = xfathhead + 学号.Text + 姓名.Text + 课程名称.Text + 上传时间.Text+"." + lx;//服务器文件相对路径;
                if (System.IO.File.Exists(fullpath))
                {
                    string alert = "已上传过同名文件,请重新选择!";
                    Response.Write(" <script> alert( '" + alert + " ') </script> ");
                    Label2.Text = "已上传过同名文件,请重新选择!";
                    return alert;
                }
                else
                {
                    fp.PostedFile.SaveAs(fullpath);//上传,但是这个函数会覆盖同名文件,请慎用;
                    Response.Write("<script>alert('上传成功!');</script>");
                    Label2.Text = "当前材料信息:" + path;
                    Label2.Visible = true;
                    return path;
                }
            }
        }

  • 相关阅读:
    Windows CMD 配置 启动 服务
    Starting a Service
    socket 相关文章
    Qt GUI程序带命令行
    socket 双向
    winsock Options
    winsock 主动切断连接 Connection Setup and Teardown
    在 u 开头的单词前面,用 a 还是 an
    Web自动化----搭建基本环境
    Python----yield 生成器
  • 原文地址:https://www.cnblogs.com/gull/p/1874555.html
Copyright © 2011-2022 走看看