Page 1 of 1

How to get file extension

Posted: 21 Jun 2017
by AlexStenAlexSten
hello,
I'm working with Forms Designer from few months and would need some help.
Is it possible in a document library, via Forms Designer, to get the file name with extension in the field "NAME"?
I can create a custom view in SharePoint displaying more NAME fields, with file extension, but I don't know how to get this info in Forms Designer.
My task is to have in FD the field "NAME" with link to the file and the file type. Or at least to have the "File Type" in another field in the form.
test_file_type.png
test_file_type.png (14.08 KiB) Viewed 2942 times
thank you

Re: How to get file extension

Posted: 21 Jun 2017
by Dmitry Kozlov
Hi,
Not sure that I got you. Where do you want to display an extension - in a Related Items control or as a separate field in a form?

Re: How to get file extension

Posted: 23 Jun 2017
by AlexStenAlexSten
hi Dmtry,
I'd need to display the extension or the full filename + extension in a separate field in the form.
I will have to get the file extension, because based on the extension, I will enable or disable by code some features (ie. save the form data).
Hope this is more clear. Thank you

Re: How to get file extension

Posted: 23 Jun 2017
by Dmitry Kozlov
Hi Alex,
You can get an extension from the FileLeafRef control via JavaScript:

Code: Select all

fd.field('FileLeafRef').control()._el().find('.ms-fileField-fileExt').text()

Re: How to get file extension

Posted: 26 Jun 2017
by AlexStenAlexSten
Thank you very much Dmitry. It works well!
Just for "contribute" to the forum in some way, below the solution I was working on. As you can see it works, but is much more complex than yours.
Thanks a lot

>>>>

$(function ()
{
// begin work to call across network
var requestUri = _spPageContextInfo.webAbsoluteUrl +
"/_api/web/lists/getByTitle('a_TEST_documeto_PDF')/items?$select=FileLeafRef,File_x0020_Type,File/Name,File/Title&$expand=File";

// execute AJAX request
$.ajax({
url: requestUri,
type: "GET",
headers: { "ACCEPT": "application/json;odata=verbose" },
success: function (data) {
$.each(data.d.results, function(i,result) {
alert(result.FileLeafRef +" | "+ result.File.Name + " | "+result.File_x0020_Type + " | "+ result.File.Title);
});
},
error: function () {
alert("Failed to get details");
}
});
});
>>>>>>