PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
New WINDEV Mobile 24 feature!
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
URIToFile (Function)
In french: URIVersFichier
Saves, in the background, the content of a resource (image, text, etc.) identified by its URI in an external file.
Example
// Open the system window to select a pdf
UriResource is URI = URISelect("application/pdf")
IF NOT ErrorOccurred THEN
// Save the resource in the application directory
URIToFile(UriResource, "document.pdf", ProcSave)
INTERNAL PROCEDURE ProcSave (bResult, sPath)
IF bResult THEN
ToastDisplay("Saved successfully")
ELSE  
ToastDisplay("Unable to save")
END
END
END
// Save a resource with conversion

// Open the system window to select a resource
UriResource is URI = URISelect()
IF NOT ErrorOccurred THEN
// Displays the name of the selected resource
Info(URIGetInfo(UriResource, uriInfoName))
END

UriResource is URI = URISelect()
IF NOT ErrorOccurred THEN
// Retrieves the MIME type into which the resource can be converted
sMIMEType is string = URIGetInfo (UriResource, uriInfoConversionType)
IF sMIMEType <> "" THEN
// If there are several possible MIME types
IF StringCount(sMIMEType, TAB) > 1 THEN
// Ask the user to choose the type to use
...
END
// Save the resource on the device
URIToFile(UriResource, SysDirExternalStorage(1, sseAppDocument), ...
ProcEndSave, sMIMEType)
INTERNAL PROCEDURE ProcEndSave (bResult, sResourcePath)
IF bResult THEN
ToastDisplay(StringBuild("File saved (%1)", ...
sResourcePath))
END
END
END
END
Syntax
URIToFile(<URI> , <Path> , <Procedure> [, <MIME type>])
<URI>: URI or character string variable
URI or character string variable that identifies the resource to save.
<Path>: Character string
Corresponds to:
  • a directory path (this directory must exist): the resource will be saved in this directory. The name of the created file will correspond to the original name of the resource, and its extension will depend on the format used to save it (see notes).
  • A full or relative file path. If the file already exists, it will be overwritten.
    Caution: the file extension will not be modified even if the resource had to be converted to another format to be saved.
The full path of the saved file will be passed as a parameter of the procedure called once the save has been completed.
<Procedure>: Name of WLanguage procedure
Name of WLanguage procedure ("callback") called once the save has been completed. This procedure has the following format:
PROCEDURE <Procedure name> (<Result>, <Path>)
where:
  • <Result> is boolean:
    • True if the save has been completed,
    • False otherwise. To retrieve the details of the error, use ErrorInfo before any other call to a WLanguage function (which would reinitialize the error).
  • <Path> is a character string that corresponds to the full file path used for saving.
<MIME type>: Optional character string
MIME type corresponding to the format in which the resource must be saved (see Notes).
If this parameter is not specified or corresponds to an empty string (""), the resource will be saved in its original format if possible or it will first be converted to a default format.
Remarks
  • To select a resource and obtain its URI, use, for example, URISelect.
  • When the resource to save does not come from the device's file system, the content provider that manages the resource may need to convert this resource. This is usually the case if no application on the device can manage the original format of the resource. It is possible to specify the conversion format of the resource by entering the parameter <MIME type>. To find out the MIME type into which a resource can be converted, use URIGetInfo with the constant uriInfoConversionType. If this function returns an empty string (""), the resource cannot be saved. In this case, do not call URIToFile on this resource, since it will fail.
    Example:
    a Microsoft Word file (.doc or.docx) is selected using URISelect. This file is on Google Drive and no application on the device can handle this type of document. When saving this resource, the content provider will automatically convert this resource to PDF format. In this case, URIGetInfo used with the constant uriInfoConversionType will return the following string: "application/pdf + TAB + .pdf".
Component : wd240android.jar
Minimum required version
  • Version 24
Comments
Click [Add] to post a comment