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

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.Remoting.Contexts;
    using System.Web;
    using System.Web.Services;
    using System.Web.SessionState;
    using System.Web.UI.WebControls;
    using DSJKYWeb.Common;
    using DSJKYWeb.DSJKYWebHandler;
    using System.Configuration;

    namespace DSJKYWeb.WebHandler
    {
        
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        public class EleUploadHandler : IHttpHandler, IRequiresSessionState
        {
            private HttpContext context = null;
            public void ProcessRequest(HttpContext _context)
            {
                _context.Response.ContentType = "text/plain";
                _context.Response.Charset = "utf-8";
                context = _context;
                HttpPostedFile file = context.Request.Files["Filedata"];
                string id = context.Request["id"];
                #region 上传文本保存的根目录
                string strpath = ConfigurationManager.AppSettings["PassengerDeviceMan"].ToString();
                if (!Directory.Exists(context.Server.MapPath(strpath)))
                {
                    Directory.CreateDirectory(context.Server.MapPath(strpath));
                }
                string uploadPath = context.Server.MapPath(strpath);

                #endregion

                var ret = new EleUploadRet();
                string _path = string.Empty;
                if (file == null)
                    return;
                _path += strpath + "\";
                 var upname="";
                  upname = Guid.NewGuid().ToString() + "." + file.FileName.Split('.')[file.FileName.Split('.').Length - 1];
                  _path += upname;
                file.SaveAs(context.Server.MapPath(_path));
                ret.SavePath = _path;
                ret.name = upname;
                context.Response.Write(AjaxResult.Success(ret).ToString());
            }
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }


        /// <summary>
        /// 上传后统一返回类
        /// PS:所有的返回请使用这个类,不要修改原来的已经存在属性,如果你获取新的返回信息,请添加一个新的属性即可
        /// </summary>
        class EleUploadRet
        {
            public string SavePath { get; set; }
            public string name { get; set; }
        }
    }

    萌橙 你瞅啥?
  • 相关阅读:
    人的一生为什么要努力 &1
    数据库_数据库系统概论
    电子商务安全
    虚拟专用网技术
    人的一生为什么要努力
    数据备份与恢复技术
    入侵检测技术
    简历模板连接
    防火墙技术
    字节与位
  • 原文地址:https://www.cnblogs.com/daimaxuejia/p/6689723.html
Copyright © 2011-2022 走看看