This is a migrated thread and some comments may be shown as answers.

File name and extension

1 Answer 115 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Hamza
Top achievements
Rank 1
Hamza asked on 18 Jan 2021, 03:35 PM

Hi,

I looked everywhere to get a selected item from a file explorer in C#, but nothing worked.

I need only the name and the extension to update my database, is that possible?

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 19 Jan 2021, 06:48 PM

Hi Hamza,

The file-selecting functionality of RadFileExplorer is implemented on the client-side and such is available only on the client. You can access the selected file with the following logic:

                var selectedFile = $find("RadFileExplorer1").get_selectedItem();
                var fileName = selectedFile.get_name();
                var ext = selectedFile.get_extension()

If you need to access this information on the server, you could store the selected file name into a hidden field and access its value later on the server. For example, you can store it in the OnClientItemSelected event-handler:

        <telerik:RadFileExplorer ID="RadFileExplorer1" runat="server" OnClientItemSelected="onItemSelected">
            <Configuration ViewPaths="~/" DeletePaths="~/" UploadPaths="~/" />
        </telerik:RadFileExplorer>
        <asp:HiddenField ID="SelectedFileFld" runat="server" />
        <script>
            function onItemSelected(fileExplorer, args) {
                var selectedItem = args.get_item();
                var fileName = selectedItem.get_name();
                $get("SelectedFileFld").value = fileName;
                //access SelectedFileFld.Value on the server when you need it
            }
        </script>

 

Regards,
Vessy
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
FileExplorer
Asked by
Hamza
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Share this question
or