Пример #1
0
        private void UploadImage()
        {
            HttpResponse response = HttpContext.Current.Response;

            try
            {
                ImageProperty imageProperty = GetPostedImageProperty();
                string        opText        = WebUtility.GetRequestFormString("clientOPHidden", string.Empty);
                string        op            = !string.IsNullOrEmpty(opText) ? opText.Split(',')[0] : "";      //WebUtility.GetRequestFormString("clientOPHidden", string.Empty).Split(',')[0];
                string        inputName     = !string.IsNullOrEmpty(opText) ? opText.Split(',')[2] : "";      //WebUtility.GetRequestFormString("clientOPHidden", string.Empty).Split(',')[1];

                HttpPostedFile file = GetPostFile(inputName);

                if (file != null)
                {
                    if (this.FileMaxSize > 0 && file.ContentLength > this.FileMaxSize)
                    {
                        response.Write(GetResponseTextScript(string.Format("您上传的文件超过了{0}字节。", this.FileMaxSize)));
                        response.Write(GetClientControlInvokeStript(GetPostedControlID(), "uploadFail", "document.getElementById('responseInfo').value", ""));
                        return;
                    }

                    string filePath = string.Empty;

                    ImageUploadHelper.UploadFile(this, file, imageProperty.OriginalName, imageProperty.NewName, out filePath);
                    imageProperty.FilePath = filePath.Encrypt();

                    string imgPropJsonStr = JSONSerializerExecute.Serialize(imageProperty);

                    string uploadImageShowenUrl = CurrentPageUrl + string.Format("?imagePropID={0}&filePath={1}", imageProperty.ID, filePath.Encrypt());

                    response.Write(GetResponseTextScript(imgPropJsonStr));

                    response.Write(GetUploadImageUrlByFile(uploadImageShowenUrl));

                    string paramsData = string.Format("['{0}','{1}']", "document.getElementById('responseInfo').value", uploadImageShowenUrl);

                    response.Write(GetClientControlInvokeStript(GetPostedControlID(), "uploadSuccess", "document.getElementById('responseInfo').value", "document.getElementById('uploadImageUrlByFile').value"));
                }
            }
            catch (System.Exception ex)
            {
                response.Write(GetResponseTextScript(ex.Message));
                response.Write(GetClientControlInvokeStript(GetPostedControlID(), "uploadFail", "document.getElementById('responseInfo').value", ""));
            }
            finally
            {
                response.End();
            }
        }
Пример #2
0
        protected override void LoadClientState(string clientState)
        {
            object[] state = (object[])JSONSerializerExecute.DeserializeObject(clientState);

            object tempState;

            if (state[0] is object[])
            {
                object[] tempResult = (object[])state[0];
                tempState = tempResult[0];
            }
            else
            {
                tempState = state[0];
            }
            this.imgProp = JSONSerializerExecute.Deserialize <ImageProperty>(tempState);

            string postedControlID = GetPostedControlID();

            if (postedControlID.IsNullOrEmpty())
            {
                postedControlID = ((string)state[1]).Replace('_', '$');
            }

            HttpPostedFile file = GetPostFile(postedControlID);

            if (file != null)
            {
                if (this.imgProp.ID.IsNullOrEmpty())
                {
                    this.imgProp.ID = UuidHelper.NewUuidString();
                }

                this.imgProp.NewName = UuidHelper.NewUuidString() + Path.GetExtension(imgProp.OriginalName);
                this.imgProp.Changed = true;

                string filePath;

                ImageUploadHelper.UploadFile(this, file, this.imgProp.OriginalName, this.imgProp.NewName, out filePath);
            }
        }