public override bool IsValid(object value)
        {
            if (value == null)
            {
                if (AllowNull)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            var file = (IFormFile)value;
            var ext  = Path.GetExtension(file.FileName).ToLower().Replace(".", "");

            return(Exts.Contains(ext));
        }
Example #2
0
        /// <summary>
        /// 添加TabPage通过TabBundle
        /// 1. 打开文件
        /// 2. 新建文件
        /// </summary>
        /// <param name="bundle">绑定TabPage与FilePath</param>
        public void Add(TabBundle bundle)
        {
            // 创建TabPage
            var form = CreateForm(EditFormClassName);

            TabPage page = CreateTabPage(bundle.TabTitle, CreateForm(EditFormClassName));

            TabBudles.Add(new TabBundle
            {
                TabTitle = bundle.TabTitle,
                IsNew    = bundle.IsNew || !((!string.IsNullOrWhiteSpace(bundle.SrcPath)) && File.Exists(bundle.SrcPath) && Exts.Contains(Path.GetExtension(bundle.SrcPath).ToLower())),
                TabPage  = page
            });
            if ((!string.IsNullOrWhiteSpace(bundle.SrcPath)) && File.Exists(bundle.SrcPath) /* && bundle.SrcFilePath.isPath()*/)
            {
                ((RichTextBox)page.Controls.Find("RichTextBox", true).FirstOrDefault()).LoadFile(bundle.SrcPath, RichTextBoxStreamType.PlainText);
            }
            bundle.TabPage = page;
            TabControl.TabPages.Add(page);
            var index = TabControl.TabPages.IndexOf(page);

            TabControl.SelectedIndex = index;
        }