• 【原】FileUpload控件上传文件


    代码
    #region 上传文件
    /// <summary>
    /// 上传文件
    /// </summary>
    public void LoadFile()
    {
    if (FileUpload1.HasFile)
    {
    string fileContentType = FileUpload1.PostedFile.ContentType;
    if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg" || fileContentType == "application/x-shockwave-flash")
    {
    string name = FileUpload1.PostedFile.FileName; // 客户端文件路径
    FileInfo file = new FileInfo(name);
    string fileName = file.Name; // 文件名称
    string webFilePath = Server.MapPath("../Files/advert/" + fileName); // 服务器端文件路径
    string houzhui = System.IO.Path.GetExtension(name);
    if (!File.Exists(webFilePath))
    {
    try
    {
    FileUpload1.SaveAs(webFilePath);
    // 使用 SaveAs 方法保存文件
    Response.Write("<script>alert('文件上传成功!!')</script>");
    }
    catch (Exception ex)
    {
    throw new Exception("提示:文件上传失败,失败原因" + ex.Message);
    }
    }
    else
    {
    Response.Write(
    "<script>alert('文件已经存在,请重命名后上传!')</script>");
    }
    }
    else
    {
    Response.Write(
    "<script>alert('文件类型不符!')</script>");
    }
    }
    else
    {
    Response.Write(
    "<script>alert('请选要上传的文件!')</script>");
    }

    }
    #endregion
  • 相关阅读:
    洛谷月赛 Hello World(升级版)
    codevs1001 舒适的路线
    vijos & codevs 能量项链
    vijos 运输计划
    noip2016普及组题解和心得
    UVa 10891 Game of Sum
    UVa 10635 Prince and Princess
    某模拟题题解 2016.11.17
    贪心入门题
    某模拟题题解 2016.11.16
  • 原文地址:https://www.cnblogs.com/gebenhagen/p/1681321.html
Copyright © 2020-2023  润新知