Jump to content
Eugenio Monti

FileOpen a network file

Recommended Posts

I'm porting on Android an old app originally developed for Windows tablet.

I use FMX on C++Builder 10.2. My problem is how to port the row:

FileOpen("\\IP_address\FolderName\Filename");

I have to run app on Samsung device NOT rooted.

Which is the better approach?

Thanks in advance

Share this post


Link to post

It looks as if you want to download a file via HTTP request, like this here in a German blog.
Then you should use something like Indy IdHttpClient for that purpose, as a rough guess what you are looking for.

Share this post


Link to post
3 minutes ago, Rollo62 said:

It looks as if you want to download a file via HTTP request, like this here in a German blog.
Then you should use something like Indy IdHttpClient for that purpose, as a rough guess what you are looking for.

It doesn't look like that to me. It looks like a file read for a file named by UNC.

 

I don't think I'd be wanting to use FileOpen anywhere ever. Shouldn't you be using streams these days?

 

Having said that of course, FileOpen still works. You didn't tell us what happened when you used the old code. If you have a problem that you want some help with, then you should say what the problem is. People can't offer solutions to problems that aren't described.

 

Do you understand what \\IP_address\FolderName\Filename is? I trust you do, and that the file specified by this UNC path is available on your current target device. Is it?

  • Like 1

Share this post


Link to post

Thanks David,

I state it is an intranet application.

The goal of the (old) app is to open a text file and modifiy some vales in a row. That file is present in a Samba shared folder on a customer Windows machine

so "IP_address" is the IP of that machine and " FolderName " is the share name.

From that machine I also have to copy some image files to a local folder of Android device and viceversa.

Share this post


Link to post
2 hours ago, David Heffernan said:

You didn't tell us what happened when you used the old code. If you have a problem that you want some help with, then you should say what the problem is. People can't offer solutions to problems that aren't described.

 

Share this post


Link to post

First you have to ensure that Samba folder is accessible on Android as Samba on Linux has long history of pain and suffer. Try some advanced file manager like TC, Far etc.

Share this post


Link to post

Ok, I already made some tests. In my device I installed different file manager (Solid Explorer, RS File Manager) and all of them are able to connect the remote IP

and browse folders and sub-folders. That's right...but...how can I do the same programmatically with FMX?

Obviously I already tried:

FileOpen("//IP_address/FolderName/Filename");

FileOpen("IP_address/FolderName/Filename");

FileOpen("smb://IP_address/FolderName/Filename");

I'm not a Linux expert but probably I should "mount" the remote connection on local filesystem; how can I do it?

 

Share this post


Link to post
...
    <application android:persistent="%persistent%" 
        android:restoreAnyVersion="%restoreAnyVersion%" 
        android:label="%label%" 
        android:debuggable="%debuggable%" 
        android:largeHeap="%largeHeap%"
        android:icon="%icon%"
        android:theme="%theme%"
        android:hardwareAccelerated="%hardwareAccelerated%">
        <!-- **** ADD THIS SECTION **** -->
        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.embarcadero.yourAppName.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/>
        </provider>

<%application-meta-data%>
        <%services%>
...

 

Take a look here: Delphi Android file open failure with API 26 - Stack Overflow

maybe hat works, and maybe you first have to ask access with credentials?

 

editing goes wrong in the forum sometimes 🙂

 

 

 

 

Edited by mvanrijnen

Share this post


Link to post
22 minutes ago, Eugenio Monti said:

No exceptions, no errors. Simply it returns INVALID_HANDLE_VALUE.

Well, there will be an error code. You have to retrieve it. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×