web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / How to retrieve file n...
Power Pages
Answered

How to retrieve file names from File Upload form

(0) ShareShare
ReportReport
Posted on by 16

Hi

 

I have a basic file upload form which uploads one/multiple files to notes.

I need to fetch the file names user has chosen to upload and put a validation for if user has uploaded all the required files.

 

how do we retrieve the list of the file using custom js ? or are there any other way to achieve the same.

Categories:
I have the same question (0)
  • H V Profile Picture
    1,510 on at

    Hi @sss333 

     

    • Go to Your Basic Form
    • Click on Additional Settings
    • Add below code in Custom JavaScript

     

     

     

    $(document).ready(function() {
    	$('#AttachFile').change(function() {
     var fileList = $('#AttachFile')[0].files;
    		if(fileList.length > 0)
    		{
    			 for (var i = 0; i < fileList.length; i++)
    			 {
    				console.log(fileList[i].name);
    			 }
    		}
     });
    });

     

     

     

     

    You can get file name using above code.

     

    --------------------------
    If you like this post, give a Thumbs up. Where it solved your query, Mark as a Solution so it can help other people!

  • sss333 Profile Picture
    16 on at

    Thanks @hardikv , this worked.

     

    Actually I am trying to check if user has uploaded required files and if not then show them an error message on top of my form.

    Can you help on that too? how do I show an error message in case that file name validation part fails.

  • H V Profile Picture
    1,510 on at

    Hi @sss333 

     

    Can you please share screenshot of your form and inspect element of your field?

  • sss333 Profile Picture
    16 on at

    Hi @hardikv 

     

    Just an update here. We have to validate no. of files the user should be able to upload and should not allow it to be more than 2. In case it is, we have to show an error message.

     

    I have written this custom JS code and added to the advanced settings of my Basic Form(attachment enabled) but it does nothing when I select > 2 files or < 2 files.

     

    $(document).ready(function(){
    $("#AttachFile").change(validateFileNames);
    validateFileNames();
    });

    function validateFileNames() {
    const files = $("#AttachFile").files;
    if(files.length!=2){
    alert("Please select only 2 files");
    }
    }
     
  • Verified answer
    H V Profile Picture
    1,510 on at

    Hi @sss333 

     

    Please use below code:

    If you want to validate that user can not select more than 2 files at a time:

     

    $(document).ready(function() {
    	$('#AttachFile').change(function() {
     var fileList = $('#AttachFile')[0].files;
    		if(fileList.length > 2)
    		{
     $('#AttachFile').val("");
    			 alert("You can not select more than 2 files.");
    		}
     });
    });

     

     

    --------------------------
    If you like this post, give a Thumbs up. Where it solved your query, Mark as a Solution so it can help other people! 

  • H V Profile Picture
    1,510 on at

    Hi @sss333 

     

    Did that help to solve your issue? Can you mark as the answer so it helps other users?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Pages

#1
DP_Prabh Profile Picture

DP_Prabh 41

#2
oliver.rodrigues Profile Picture

oliver.rodrigues 35 Most Valuable Professional

#3
rezarizvii Profile Picture

rezarizvii 28

Last 30 days Overall leaderboard