コード例 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         NativeWebFacade aideNativeWebFacade = new NativeWebFacade();
         PagerSet        pagerSet            = aideNativeWebFacade.GetList(ConfigInfo.Tablename, 1, 10000, "", " ORDER BY ConfigID ASC");
         rptDataList.DataSource = pagerSet.PageSet;
         rptDataList.DataBind();
     }
 }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {
            //登陆验证
            Base_Users logonUser = FacadeManage.aidePlatformManagerFacade.GetUserInfoFromCache();

            if (logonUser == null || logonUser.RoleID != 1)
            {
                context.Response.Write("无上传图片权限");
                return;
            }

            //文件保存地址
            string typeInfo = GameRequest.GetQueryString("type");
            string savePath = string.Empty;
            string saveUrl  = string.Empty;

            switch (typeInfo)
            {
            case "issue":
                savePath = "/Upload/Issue/";
                saveUrl  = "/Upload/Issue/";
                break;

            case "match":
                savePath = "/Upload/Match/";
                saveUrl  = "/Upload/Match/";
                break;

            case "rules":
                savePath = "/Upload/Rules/";
                saveUrl  = "/Upload/Rules/";
                break;

            case "shop":
                savePath = "/Upload/Shop/";
                saveUrl  = "/Upload/Shop/";
                break;

            case "news":
                savePath = "/Upload/News/";
                saveUrl  = "/Upload/News/";
                break;

            default:
                savePath = "/Upload/News/";
                saveUrl  = "/Upload/News/";
                break;
            }

            //文件属性
            Hashtable extTable = new Hashtable();

            extTable.Add("image", "gif,jpg,jpeg,png,bmp");
            extTable.Add("flash", "swf,flv");
            extTable.Add("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb");
            int maxSize = 1024 * 1024;

            //验证文件
            this.context = context;
            HttpPostedFile imgFile = context.Request.Files["imgFile"];

            if (imgFile == null)
            {
                ShowError("请选择文件。");
                return;
            }
            try
            {
                System.Drawing.Image image = System.Drawing.Image.FromStream(imgFile.InputStream);
                image.Dispose();
            }
            catch
            {
                ShowError("非法文件,目前只支持图片格式文件,对您使用不便感到非常抱歉。");
                return;
            }

            string dirPath = context.Server.MapPath(savePath);

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }
            string dirName = context.Request.QueryString["dir"];

            if (string.IsNullOrEmpty(dirName))
            {
                dirName = "image";
            }
            if (!extTable.ContainsKey(dirName))
            {
                ShowError("目录名不正确。");
                return;
            }
            string fileName = imgFile.FileName;
            string fileExt  = Path.GetExtension(fileName).ToLower();

            if (imgFile.InputStream == null || imgFile.InputStream.Length > maxSize)
            {
                ShowError("上传文件大小超过限制。");
                return;
            }
            if (string.IsNullOrEmpty(fileExt) || Array.IndexOf(((string)extTable[dirName]).Split(','), fileExt.Substring(1).ToLower()) == -1)
            {
                ShowError("上传文件扩展名是不允许的扩展名。\n只允许" + ((string)extTable[dirName]) + "格式。");
                return;
            }

            //创建文件夹
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            //保存图片
            string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
            string filePath    = dirPath + newFileName;

            imgFile.SaveAs(filePath);

            //返回成功信息
            NativeWebFacade nativeWebFacade = new NativeWebFacade();
            ConfigInfo      configInfo      = nativeWebFacade.GetConfigInfo(EnumerationList.SiteConfigKey.SiteConfig.ToString());
            string          imageDomain     = configInfo == null ? "" : configInfo.Field3;

            string    fileUrl = imageDomain + saveUrl.Replace("Upload/", "") + newFileName;
            Hashtable hash    = new Hashtable();

            hash["error"] = 0;
            hash["url"]   = fileUrl;
            context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
            context.Response.Write(JsonMapper.ToJson(hash));
            context.Response.End();
        }