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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Client side Validation...
Power Apps
Answered

Client side Validation on File Field Type

(0) ShareShare
ReportReport
Posted on by 41

Hello everyone,

Thanks for reading my question.

I've created a Field of type File and place it on the form (model driven app). I need to do basic validation of the file such as File extension and File content. Now, with the help of Dataverse REST Builder I've the code to find the file name/extension & file content but the challenge is if I run the code on the fieldOnChange then the needed information doesn't exist in the database by the time. So, I need to find some other event on which I can trigger the code.

FileOnChange.png

 

 

this.fileToProcessOnChange = function(executionContext){ 
 prg_DataTransfer.checkFileExtension(executionContext);
 }

 this.checkFileExtension = function (executionContext){
 $.ajax({
 type: "GET",
 url: Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.2/prg_temporarydatas(cfb732f7-7acd-4193-9bfc-d4b352669f1c)?$select=prg_filetoprocess_name",
 headers: {
 "OData-MaxVersion": "4.0",
 "OData-Version": "4.0",
 "Content-Type": "application/json; charset=utf-8",
 "Accept": "application/json",
 "Prefer": "odata.include-annotations=*"
 },
 async: true,
 success: function (data, textStatus, xhr) {
 var result = data;
 //console.log(result);
 // Columns
 var prg_temporarydataid = result["prg_temporarydataid"]; // Guid
 var prg_filetoprocess_name = result["prg_filetoprocess_name"]; // Text
 console.log("File Name: " + prg_filetoprocess_name);
 },
 error: function (xhr, textStatus, errorThrown) {
 console.log(xhr);
 }
 });
 }

 

 

 

I have the same question (0)
  • Verified answer
    Guido Preite Profile Picture
    1,488 Super User 2024 Season 1 on at

    I suppose your goal is to stop the user to upload a file if doesn't follow a specific filename/extension?

    for example only uploading files like 2022*.pdf

     

    I think it's difficult to run this logic at client-side, my suggestion is to check if you can get the name inside a sync pre plugin and eventually stop there, it's the most robust way to stop the upload.

     

  • Zohaib Uddin Khan Profile Picture
    41 on at

    Your understanding is absolutely correct. I need to validate the uploaded file extension and later need to check the format of the file.

     

    Thanks for the suggestion and giving an alternate option to go with the plugin approach.

     

    If you don't mind can I ask why are you saying difficult to run at client-side? Because, its a client-side code but I'm unable to find the right event to trigger the code. Even, I'm happy to trigger the code once the file is uploaded. Does it make sense? If I'm talking total non-sense please ignore me! 😉

     

    Thanks again for your reply, appreciated!

  • Guido Preite Profile Picture
    1,488 Super User 2024 Season 1 on at

    beside the fact that by your tests client-side check is not successful:

    1) client-side logic can be easily disabled

    2) the upload can happen outside the web app client (directly by API for example)

    in both these scenarios the plugin approach will always run

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 368 Super User 2026 Season 1

#1
Kalathiya Profile Picture

Kalathiya 368 Super User 2026 Season 1

#3
WarrenBelz Profile Picture

WarrenBelz 318 Most Valuable Professional

Last 30 days Overall leaderboard