Multimedia field optional

Apr 28, 2009 at 10:54 AM
Hello,

I am using Multimedia field and always works fine. Just I have got a problem: always is mandatory. Even if I configure the column as optional in the content type. 

What could I do for solving this problem?

Thanks in advance.
Apr 28, 2009 at 12:18 PM

I tried to understand the code source and modified the following:

In MultimediaField.cs:

public override string GetValidatedString(object value){
 MultimediaFieldValue multimediafieldValue = value as MultimediaFieldValue;
 if (multimediafieldValue == null)
 return String.Empty;
 /*
 if (String.IsNullOrEmpty(multimediafieldValue.Url) || String.IsNullOrEmpty(multimediafieldValue.Height) || String.IsNullOrEmpty(multimediafieldValue.Width))
 throw new SPFieldValidationException(SPResource.GetString(Strings.MissingRequiredField));
 */
 return value.ToString();
}

In MultimediaWebControl.cs:

public override void Validate(){
 if (((base.ControlMode != SPControlMode.Display) && base.IsValid) && this.Visible){
 base.Validate();

 MultimediaFieldValue value = (Value as MultimediaFieldValue);

 //if (value != null)
 if (value.Url != null && !value.Url.Trim().Equals("")){
  string url = value.Url.ToLower();
  if (!url.EndsWith(".avi") && !url.EndsWith(".swf") && !url.EndsWith(".pdf") && !url.EndsWith(".mov") && !url.EndsWith(".mpeg") && !url.EndsWith(".mpg") && !url.EndsWith(".wmv"))
  {
   base.ErrorMessage = url + "**Multimedia file not supported. This controls supports QuickTime (.mov), Flash (.swf), MPEG videos (.mpeg,.mpg), Windows Media Videos (.avi or .wmv) and Acrobat Reader PDF (.pdf) files!";
   base.IsValid = false;
  }
  else
   base.IsValid = true;
 }
}

Hope this helps somebody.