Get FileExtension using macro.

Yowaraj Chhetri asked on September 14, 2018 07:11

Hi,

  1. How to get file extension of a file uploaded as a File data type using macro?

  2. I got 2 fields, "File Upload" (File Datatype)-which is used to upload file using direct uploader form control. And another field "File Extension"-this field is to store the extension of file uploaded to "File Upload" field. "File Extension" depends on "File Upload", so in Field Advanced setting of page types, in the visibility condition property I need to write a macro to get file extension of the file upload to "File Upload" field. How to write that macro. I tried but does not work/may be I dont know the exact macro. Thanks in advanced

Correct Answer

Rui Wang answered on September 18, 2018 15:35

Why do you need to store the Extension in a separate field if you can get it for display using the macro I mentioned above?

If you do want to populate a field from another field, you cannot use macro as it's not for data population. You will have to use event handler to get the extension and populate the other field during CREATE or UPDATE event for the xFile page type.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Arun Kumar answered on September 14, 2018 09:19 (last edited on September 14, 2018 09:23)

You need to handle the file upload control change event. Its better to do that using jQuery on page load. For dependents fields to show there has to be a page postback which will not happen in case of file upload.

$(document).ready(function(){
  $(".ext").closest("tr").hide();
  $(".upload input").change(function(){
  var fileName= $(this).val();
  var extention= fileName.substr( (fileName.lastIndexOf('.') +1) );
  if(extention)
  {
     $(".ext").closest("tr").show();
     $(".ext").val(extention);
  }
 })
});

Here ext is the Extention field control CSS class and upload is file upload control CSS class which you can set at field advanced properties.

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on September 14, 2018 21:18 (last edited on December 10, 2019 02:31)

the macro for getting the File Page type extension in a repeater is {% Object.AllAttachments.FirstItem.AttachmentExtension |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Yowaraj Chhetri answered on September 17, 2018 04:54

Image Text

If you check this image,there is File field (which uploads the file from Windows file system) and there is another field "File Extension" which should get the file extension of file that is upload to "File" field. I am currently at the Form tab creating my file pagetype content. https://drive.google.com/open?id=18t8Xk4wi0AQmeI1rWwy_TE2siH8m-_yO

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on September 17, 2018 16:36

Yowaraj, this is what the out of box file page type looks like, there is no File Extension field. Is that something you customized?

Image Text

0 votesVote for this answer Mark as a Correct answer

Adelphi Digital answered on September 18, 2018 08:05 (last edited on September 18, 2018 08:06)

Hi Rui Wang,

I created a separate pagetype "xFile" with few fields, where File is of File Datatype. My question is I want to get the file extension in the "FileExtension" field when I upload a document file (pdf/doc,etc..) to the "File" field. This could be done using macro to get the extension of the file upload from the field "File" into the field extension.But I dont know how to get that extension in from one field to another.

file_image file_extension

Thanks in advance.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.