Пример #1
0
        /// <summary>
        /// 获取Form传值
        /// </summary>
        /// <param name="fieldItem"></param>
        /// <returns></returns>
        public String GetWebFormValue(DNNGo_PowerForms_Field fieldItem)
        {
            String WebFormValue = String.Empty;

            //创建控件的Name和ID
            TemplateFormat xf          = new TemplateFormat(this);
            String         ControlName = xf.ViewControlName(fieldItem);
            String         ControlID   = xf.ViewControlID(fieldItem);


            if (fieldItem.FieldType == (Int32)EnumViewControlType.CheckBox)
            {
                WebFormValue = WebHelper.GetStringParam(Request, ControlName, "");
                WebFormValue = !String.IsNullOrEmpty(WebFormValue) && WebFormValue == "on" ? "true" : "false";
            }
            else if (fieldItem.FieldType == (Int32)EnumViewControlType.FileUpload)
            {
                if (Request.Files != null && Request.Files.Count > 0)
                {
                    HttpPostedFile hpFile = Request.Files.Get(ControlName);
                    if (hpFile != null && hpFile.ContentLength > 0)
                    {
                        //To verify that if the suffix name of the uploaded files meets the DNN HOST requirements
                        Boolean retValue = FileSystemUtils.CheckValidFileName(hpFile.FileName);
                        if (retValue)
                        {
                            WebFormValue = String.Format("Url://{0}", FileSystemUtils.UploadFile(hpFile, this));//存放到目录中,并返回
                        }
                    }
                }
            }
            else if (fieldItem.FieldType == (Int32)EnumViewControlType.MultipleFilesUpload)
            {
                String WebUploads = WebHelper.GetStringParam(Request, ControlName, "");
                if (!String.IsNullOrEmpty(WebUploads) && WebUploads != "[]")
                {
                    List <Resource_FilesStatus> Uploads = jsSerializer.Deserialize <List <Resource_FilesStatus> >(WebUploads);
                    if (Uploads != null && Uploads.Count > 0)
                    {
                        List <String> fileurls = new List <string>();
                        foreach (var UploadFile in Uploads)
                        {
                            fileurls.Add(String.Format("Url://{0}", FileSystemUtils.CopyFile(UploadFile, this)));
                        }
                        WebFormValue = Common.GetStringByList(fileurls, "<|>");
                    }
                }
            }
            else if (fieldItem.FieldType == (Int32)EnumViewControlType.DropDownList_Country)
            {
                var tempWebFormValue = WebHelper.GetStringParam(HttpContext.Current.Request, ControlName, "");

                var Countrys = new ListController().GetListEntryInfoItems("Country");
                foreach (var Country in Countrys)
                {
                    if (Country.Value == tempWebFormValue)
                    {
                        WebFormValue = Country.Text;
                        break;
                    }
                }
            }
            else
            {
                WebFormValue = WebHelper.GetStringParam(Request, ControlName, "");

                if (!(fieldItem.FieldType == (Int32)EnumViewControlType.RichTextBox))
                {
                    //非富文本框时,需要过滤掉XSS特殊字符
                    WebFormValue = Common.LostXSS(WebFormValue);
                }

                //如果提示的值和输入的值一样的情况,就过滤掉该值 *** 有点争议的地方
                if (WebFormValue == fieldItem.ToolTip && fieldItem.DefaultValue != WebFormValue)
                {
                    WebFormValue = string.Empty;
                }
            }

            return(WebFormValue);
        }