How to get file extension

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
AlexStenAlexSten
Posts: 31
Joined: Fri Apr 07, 2017

21 Jun 2017

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 2938 times
thank you
ciao,
Ale Stendardo

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

21 Jun 2017

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?

User avatar
AlexStenAlexSten
Posts: 31
Joined: Fri Apr 07, 2017

23 Jun 2017

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
ciao,
Ale Stendardo

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

23 Jun 2017

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()

User avatar
AlexStenAlexSten
Posts: 31
Joined: Fri Apr 07, 2017

26 Jun 2017

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");
}
});
});
>>>>>>
ciao,
Ale Stendardo

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 5 guests