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; }
        }
    }

    萌橙 你瞅啥?
  • 相关阅读:
    【转载】多个集合合并成没有交集的集合-实现
    [遇见时光]美团测试实习生面试
    [遇见时光]中科院分词工具NLPIR,Not valid license or your license expired!
    html a标签的target属性
    使用EditPlus技巧,提高工作效率(自动文成文件、语法文件下载)
    android textView 替文字添加下划线 删除线
    Android把自己应用加入到系统文件分享中
    addFooterView 方法注意调用顺序
    android打开当前应用市场简单方法 (ActivityNotFoundException 异常解决)
    The currently displayed page contains invalid values异常
  • 原文地址:https://www.cnblogs.com/daimaxuejia/p/6689723.html
Copyright © 2011-2022 走看看