You need to sign in to do that
Don't have an account?

How to get the file name in the apex:inputFile tag
Hi,
Is there a way to capture the fileName in the apex:inutFile after choosing the file and default it to the value in the apex:inputField? I am doing below (snippet) but i get the file name as undefined all the time - any idea why or any other better way of doing it?
<script>
function defaultName()
{
var fileName2 = document.getElementById("thePage:theForm:fileInput");
var documentName = document.getElementById("thePage:theForm:docName");
documentName.value = fileName2.value; ------> I get undefined here?? How do i get the fileName???
return true;
}
</script>
<apex:inputFile value="{!con}" contentType="{!type}" fileName="{!name}" id="fileInput" onchange="javascript:defaultName()"/>
<apex:inputField value="{!docName}" id="docName"/>
thanks so much.
Hi,
Try the below code snippet as reference:
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Hi , there is no need to use javascript to get the file nam eof the uploaded file.
you can use below snippet to get that
<apex:inputFile value="{!contentFile}" filename="{!nameFile}" />
create nameFile as a string variable in you r contrioller, you will get the name of file in that.
public with sharing class MyController {
// To hold the name of file
public String nameFile { get; set; }
}
Please accept this as a solution if it solve your issue
Hi,
Try the below code snippet as reference:
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.