当前位置: 首页>>代码示例>>C#>>正文


C# Validator.IsFileName方法代码示例

本文整理汇总了C#中Validator.IsFileName方法的典型用法代码示例。如果您正苦于以下问题:C# Validator.IsFileName方法的具体用法?C# Validator.IsFileName怎么用?C# Validator.IsFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Validator的用法示例。


在下文中一共展示了Validator.IsFileName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateFileName

    /// <summary>
    /// Validates file name. Returns new valid file name.
    /// </summary>
    /// <param name="fileName">New file name</param>
    /// <param name="result">Validation result</param>
    public string ValidateFileName(string fileName, out string result)
    {
        string newFileName = null;
        string validationResult = null;

        if (!ShowOnlyTitleAndDescription)
        {
            Validator validator = new Validator();
            fileName = ValidationHelper.GetSafeFileName(fileName.Trim());
            validationResult = validator.IsFileName(fileName, GetString("img.errors.filename")).Result;

            if (string.IsNullOrEmpty(validationResult))
            {
                newFileName = URLHelper.GetSafeFileName(fileName, CMSContext.CurrentSiteName);
                validationResult = validator.NotEmpty(newFileName, GetString("img.errors.filename")).Result;

                // Check that user input is bigger then "" and trim (DB field)
                if (string.IsNullOrEmpty(validationResult))
                {
                    if (newFileName.Length > 245)
                    {
                        newFileName = newFileName.Remove(245);
                    }
                }
            }
        }

        result = validationResult;
        return newFileName;
    }
开发者ID:hollycooper,项目名称:Sportscar-Standings,代码行数:35,代码来源:MetaDataEditor.ascx.cs

示例2: btnChangeMetaDataClick

    /// <summary>
    /// Change meta data (name, title and description).
    /// </summary>
    protected void btnChangeMetaDataClick(object sender, EventArgs e)
    {
        // Check that user input is valid string
        Validator validator = new Validator();
        string fileName = ValidationHelper.GetSafeFileName(txtFileName.Text.Trim());
        string result = validator.IsFileName(fileName, GetString("img.errors.filename")).Result;
        if (string.IsNullOrEmpty(result))
        {
            string newName = URLHelper.GetSafeFileName(fileName, SiteContext.CurrentSiteName);
            result = validator.NotEmpty(newName, GetString("img.errors.filename")).Result;

            // Check that user input is smaller then DB field
            if (newName.Length <= 245)
            {
                string title = metaDataEditor.ObjectTitle;
                string description = metaDataEditor.ObjectDescription;

                CreateVersion(imgHelper.SourceData, newName, title, description);

                if (LoadingFailed)
                {
                    ShowError(GetString("img.errors.processing"));
                }
                else
                {
                    ShowChangesSaved();
                }
            }
            else
            {
                ShowError(GetString("img.errors.filetoolong"));
            }
        }

        if (!string.IsNullOrEmpty(result))
        {
            ShowError(GetString("img.errors.filename"));
        }
    }
开发者ID:arvind-web-developer,项目名称:csharp-projects-Jemena-Kentico-CMS,代码行数:42,代码来源:BaseImageEditor.ascx.cs

示例3: btnChangeMetaDataClick

    /// <summary>
    /// Change meta data (name, title and description).
    /// </summary>
    protected void btnChangeMetaDataClick(object sender, EventArgs e)
    {
        // Check that user input is valid string
        Validator validator = new Validator();
        string fileName = ValidationHelper.GetSafeFileName(txtFileName.Text.Trim());
        string result = validator.IsFileName(fileName, GetString("img.errors.filename")).Result;
        if (string.IsNullOrEmpty(result))
        {
            string newName = URLHelper.GetSafeFileName(fileName, CMSContext.CurrentSiteName);
            result = validator.NotEmpty(newName, GetString("img.errors.filename")).Result;

            // Check that user input is smaller then DB field
            if (newName.Length <= 245)
            {
                string title = metaDataEditor.ObjectTitle;
                string description = metaDataEditor.ObjectDescription;

                CreateVersion(imgHelper.SourceData, newName, title, description);

                if (LoadingFailed)
                {
                    lblFileNameValidationFailed.ResourceString = LblLoadFailed.ResourceString;
                    lblFileNameValidationFailed.Visible = true;
                }
                else
                {
                    lblPropertiesInfo.Text = GetString("general.changessaved");
                    lblPropertiesInfo.Visible = true;
                }
            }
            else
            {
                lblFileNameValidationFailed.ResourceString = "img.errors.filetoolong";
                lblFileNameValidationFailed.Visible = true;
            }
        }

        if (!string.IsNullOrEmpty(result))
        {
            lblFileNameValidationFailed.ResourceString = "img.errors.filename";
            lblFileNameValidationFailed.Visible = true;
        }
    }
开发者ID:puentepr,项目名称:kentico-site-example,代码行数:46,代码来源:BaseImageEditor.ascx.cs


注:本文中的Validator.IsFileName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。