Prevent attaching BMP files to an ImagePlaceholder

BMP files are valid files when using Internet Explorer. But most other browser types
are not able to display BMP files correct. So – in an Internet scenario – it is a
good idea to prevent that BMP files can be uploaded to the MCMS Repository

There are two things to consider:

  1. upload as a local image from the file system
  2. upload to the resource gallery

Preventing upload of an BMP files from local file system to the ImagePlaceholderControl

To prevent upload of BMP files from the local file system to the ImagePlaceholderControl
an additional check needs to be added to the following file:

<CMS-InstallDir>\Server\IIS_CMS\WebAuthor\Dialogs\ResourceBrowser\ResourceBrowserCommon.js

The red lines needs to be added to the following routine: WBC_getLocalPath

    function WBC_getLocalPath(strResType) {
     document.NC_LocalForm.NC_FileData.focus();
     document.NC_LocalForm.NC_FileData.blur();
     var strLocalPath = document.NC_LocalForm.NC_FileData.value;
     
     // Check for empty or all blanks filename
     if (strLocalPath.split(" ").length == strLocalPath.length + 1) {
      alert(L_NoFileSelected_ErrorMessage);
      return null;
     }
     
     if ( strResType == IDS_RESTYPE_IMAGE ) {
      // This array defines the valid image extensions
      var arrayImageExt = new Array("gif", "jpg", "jpeg", "png", "bmp");
      var strFileExt = strLocalPath.substring( strLocalPath.lastIndexOf(".")+1
    ).toLowerCase();

      if (strFileExt == "bmp")
      {
       alert("BMP files are not supported! Please choose GIF, JPG or PNG
    instead.");
       return null;
      }

      for (var i = 0; i < arrayImageExt.length; i++) {
       if (strFileExt == arrayImageExt[i]) {
        return strLocalPath;
       }
      }
      if (!confirm(L_InvalidImageType_ErrorMessage)) {
       return null;
      }
     }
     
     if ( strResType == IDS_RESTYPE_VIDEO ) {
      // This array defines the valid video extensions
      var arrayVideoExt = new Array("asf", "asx", "avi", "mov", "mpeg", "mpg",
    "qt");
      var strFileExt = strLocalPath.substring( strLocalPath.lastIndexOf(".")+1
    );
      for (var i = 0; i < arrayVideoExt.length; i++) {
       if (strFileExt == arrayVideoExt[i]) {
        return strLocalPath;
       }
      }
      if (!confirm(L_InvalidVideoType_ErrorMessage)) {
       return null;
      }
     }
     
     return strLocalPath;
    }

Preventing upload of BMP files to the resource gallery

To prevent upload of BMP files from the local file system to the ImagePlaceholderControl
an additional check needs to be added to the following file:

<CMS-InstallDir>\Server\IIS_CMS\WebAuthor\Dialogs\ResourceBrowser\Management\ResourceCreate.aspx

The red lines needs to be added to this file:

    ...
         <!--
          function WBC_onPreview(strResType)
          {
             WBC_previewLocalResource(strResType);
             return false;
          }

          function WBC_onCancel()
          {
             window.close();
             return false;
          }

          function SG_validateType()
          {
             document.NC_LocalForm.NC_FileData.focus();
             document.NC_LocalForm.NC_FileData.blur();
             var strLocalPath = document.NC_LocalForm.NC_FileData.value;

             var strFileExt = strLocalPath.substring(
    strLocalPath.lastIndexOf(".")+1 ).toLowerCase();

             if (strFileExt == "bmp")
             {
                alert("BMP files
    are not supported! Please choose GIF, JPG or PNG instead.");
                return false;
             } 
          }

         //-->
      </script>
     </HEAD>
     <BODY class=WBC-styclsTextColor0 bgColor="<%=IDS_BODYSETTING_BGCOLOR %>"

                                       
    leftMargin="<%=IDS_BODYSETTING_LEFTMARGIN%>"

                                       
    topMargin="<%= IDS_BODYSETTING_TOPMARGIN %>">
      <FORM id="NC_LocalForm" method="post" enctype="multipart/form-data"
    runat="server" onsubmit='return SG_validateType()'>
       <table cellSpacing="0" cellPadding="0" width="100%" border="0">
        <!-- Set Dialog Title-->
        <tr>
    ...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.