API to manage file and resource paths¶
Introduction
Below is described the ResourceUri
static C# class, which represents the path (URI - Uniform Resource Identifier) of a file or a resource inside or outside the project. The same class represents the same type of data for the variables (for example the Path property of an Image object).
Below the properties in reading the ResourceUri
class and the methods that the class displays to reference files/resources are described.
Properties of a ResourceUri object
Properties |
Data type |
Description |
---|---|---|
UriType |
UriType |
Type of path contained:
|
ProjectRelativePath |
string |
Relative path of a file in relation to the ProjectFiles folder |
ApplicationRelativePath |
string |
Relative path of a file in relation to the ApplicationFiles folder |
AbsoluteFilePath |
string |
Absolute path of a file external to the project |
URI |
string |
Absolute path of a generic resource |
Depending on the value of the UriType
property of a ResourceUri
object, the other properties display a value or not, as below:
UriType |
ProjectRelativePath |
ApplicationRelativePath |
AbsoluteFilePath |
URI |
---|---|---|---|---|
URI |
- |
- |
- |
URI (for example a URL HTTP) |
ProjectRelative |
Relative path in relation to the ProjectFiles folder |
- |
- |
Absolute path |
ApplicationRelative |
- |
Relative path in relation to the ApplicationFiles folder |
- |
Absolute path |
AbsoluteFilePath |
- |
- |
Absolute path |
Absolute path |
ResourceUri.FromAbsolutePath(path)¶
Returns a ResourceUri
C# object with UriType
= AbsoluteFilePath and containing an absolute path of a file.
static ResourceUri FromAbsoluteFilePath(string path);
Arguments
path
string
Absolute path of a file.
Returns
ResourceUri
C# object that contains the path indicated in the argument.
Example
Below is an example in which the API returns an applicationRelativeResourceUri
C# object of the ResourceUri
type containing the relative path C:\Users\Michael\Desktop\Text1.txt.
var applicationRelativeResourceUri = ResourceUri.FromAbsolutePath("C:\Users\Michael\Desktop\Text1.txt");
ResourceUri.FromApplicationRelativePath(path)¶
Returns a ResourceUri
C# object with UriType
= ApplicationRelative and containing a relative path of a file in relation to the ApplicationFiles folder.
static ResourceUri FromApplicationRelativePath(string path);
Arguments
path
string
Relative path of a file in relation to the ApplicationFiles folder.
Returns
ResourceUri
C# object that contains the path indicated in the argument.
Example
Below is an example in which the API returns an applicationRelativeResourceUri
C# object of the ResourceUri
type containing the relative path Text1.txt. The object is used as an argument of the .NET API WriteAllText
to create a Text1.txt text file inside the ApplicationFiles folder.
var applicationRelativeResourceUri = ResourceUri.FromApplicationRelativePath("Text1.txt");
Log.Info(applicationRelativeResourceUri.ApplicationRelativePath);
File.WriteAllText(applicationRelativeResourceUri.Uri, "Hello world!");
ResourceUri.FromProjectRelativePath(path)¶
Returns a ResourceUri
C# object with UriType
= ProjectRelative and containing a relative path of a file in relation to the ProjectFiles folder.
static ResourceUri FromProjectRelativePath(string path);
Arguments
path
string
Relative path of a file in relation to the ProjectFiles folder.
Returns
ResourceUri
C# object that contains the path indicated in the argument.
Example
Below is an example in which the API returns a projectRelativeResourceUri
C# object of the ResourceUri
type containing the relative path Text1.txt. The object is used as an argument of the .NET API WriteAllText
to create a Text1.txt text file inside the ProjectFiles folder.
var projectRelativeResourceUri = ResourceUri.FromProjectRelativePath("Text1.txt");
Log.Info(projectRelativeResourceUri.ProjectRelativePath);
File.WriteAllText(projectRelativeResourceUri.Uri, "Hello world!");
ResourceUri.FromUri(uri)¶
Returns a ResourceUri
C# object with UriType
= Uri and containing an absolute path of a generic resource, usually a network path or a website address.
Arguments
uri
string
Absolute path of a generic resource.
Returns
ResourceUri
C# object that contains the path indicated in the argument.
Example
Below is an example in which the API returns a website
C# object of the ResourceUri
type containing the URL www.asem.it.
var website = ResourceUri.FromUri("www.asem.it");