3

sharepoint 2010 の「リンク」リストにレコードを追加しようとしています。アイテムを追加するための検証を行いたいです。このように書きました。 ここに画像の説明を入力

Google キーワードを含むリンクの入力を停止しようとしています。次のコードに何か問題がありますか。私は自分の練習のためにやっています。画像ではコードがはっきり出ていないと思います。ここに書き留めました。

if (properties.AfterProperties["vti_url"].ToString().Contains("google"))
           {
               properties.ErrorMessage = "You should not enter the google";
                 properties.Cancel = true;
           }

追加後、properties.AfterProperties["URL"].ToString().Contains("google")正常に動作しています。しかし、私のエラーページは見栄えがよくありません。これがスクリーンショットです。この問題に対して何をすべきか。 ここに画像の説明を入力

4

2 に答える 2

1

properties.AfterProperties["vti_url"]「vti_url」というフィールドがないため、私は大げさな推測をして、 と言うnullでしょう...試しましたか:

properties.AfterProperties["URL"]
于 2012-07-25T07:49:10.367 に答える
1

enter code hereHinekが言及したコメントはおそらく正しい

 /// <summary>
    /// Checks the object to see if it's null, if it isn't it will return the string value of the object.
    /// </summary>
    /// <param name="value">(object) The object you want to check.</param>
    /// <returns>(string) The string value of the object.</returns>
    public static string CheckForNullValue(object value)
    {
        string tmpValue = string.Empty;
        try
        {
            if (value != null)
            {
                if (!string.IsNullOrEmpty(value.ToString()))
                {
                    tmpValue = value.ToString();
                }
            }
        }
        catch (Exception exc)
        {
            Error.Log("Failed to check for null value Value passed in" + value, exc, Error.ErrorType_Error);
            throw exc;
        }
        return tmpValue;
    }

string url = CheckForNullValue(properties.AfterProperties["vti_url"])


if (url.Contains("Google"))   
       {   
           properties.ErrorMessage = "You should not enter the google";   
             properties.Cancel = true;   
       }   

お役に立てれば

于 2012-07-25T07:54:33.400 に答える