zoukankan      html  css  js  c++  java
  • .net文件上传,客户端用jquery file upload

    <%@ WebHandler Language="C#" Class="Handler" %>
    
    using System;
    using System.Web;
    
    
    using System.IO;
    
    
    public class Handler : IHttpHandler {
    
        /// <summary>
        /// 上传文件夹
        /// </summary>
        private const string UPLOAD_FOLDER = "~/UploadFile/";
    
        public void ProcessRequest(HttpContext context)
        {
            int resultVal = (int)ReturnVal.Failed;
            try
            {
                HttpPostedFile myFile = context.Request.Files[0];
    
                if (myFile != null)
                {
                    if (myFile.InputStream.Length != 0)
                    {
                        string originalFileName = Path.GetFileName(myFile.FileName);     //原文件名                        
                        string newFileName = string.Format("{0}_{1}", Guid.NewGuid(), originalFileName);   //新文件名---组成形式:  GUID + 下划线 + 原文件名
                        string fileAbsPath = context.Server.MapPath(UPLOAD_FOLDER) + newFileName;   //绝对路径
    
                        myFile.SaveAs(fileAbsPath);
    
                        resultVal = (int)ReturnVal.Succeed;
                    }
                    else
                    {
                        resultVal = (int)ReturnVal.FileEmpty;
                    }
                }
                else
                {
                    resultVal = (int)ReturnVal.NotSelected;
                }
            }
            catch (Exception)
            {
                resultVal = (int)ReturnVal.Failed;
            }
            finally
            {
                context.Response.Write(resultVal);
            }
        }
    
        #region## 返回值
        /// <summary>
        /// 返回值
        /// </summary>
        private enum ReturnVal : int
        {
            /// <summary>
            /// 不能上传 0 K大小的文件
            /// </summary>
            FileEmpty = -2,
    
            /// <summary>
            /// 未选中文件
            /// </summary>
            NotSelected = -1,
    
            /// <summary>
            /// 上传失败
            /// </summary>
            Failed = 0,
    
            /// <summary>
            /// 成功
            /// </summary>
            Succeed = 1
    
        }
        #endregion
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    
    }

  • 相关阅读:
    查看行业数据的站点
    OKR:团队提升的目标你真的达成了吗?
    好的OKR应该有这6个特点
    Windows批量执行Sql文件
    FISCO-BCOS-Python-SDK 在window系统的安装
    docker打开2375监听端口
    fabric-sdk-java 简单示例
    fabric智能合约
    性能测试工具(BenchmarkDotnet)
    Docker安装Jenkins教程
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090518.html
Copyright © 2011-2022 走看看