Click or drag to resize

DocumentFindUserResource Method (String)

Gets the UserResource instance with the specified path within this document's user resources.

Namespace:  Demo3D.Visuals
Assembly:  Demo3D.Core (in Demo3D.Core.dll) Version: 15.0.2.11458
Syntax
C#
public UserResource FindUserResource(
	string localPath
)

Parameters

localPath
Type: SystemString
The local path of the user resource within this document.

Return Value

Type: UserResource
The user resource matching the localPath.
Examples
C#
[Auto] CustomPropertyValue<UserResourceReference> Data;

[Auto] void OnReset(BoxVisual sender) {
    if (!sender.HasProperty("Data")) return;

    var ur = document.FindUserResource(this.Data);
    var localFile = WriteUserResourceToTemporaryFile( ur );

    if (localFile == "") return;

    var dataTable =
        Demo3D.Utilities.DataSourceImporter.ReadDataTableFromTextFile( localFile );

    File.Delete( localFile );

    foreach (var colName in dataTable.Columns) {
        print(colName);
    }
}

string WriteUserResourceToTemporaryFile(UserResource ur) {
    if (ur == null) return "";

    var ins   = ur.GetInputStream(null);
    var len   = ins.Length;
    var bytes = new byte[len];

    ins.Read( bytes, 0, (int)len );

    var tmpFile = 
        Path.Combine( Path.GetTempPath(), Path.GetFileName(ur.LocalPath) );

    File.WriteAllBytes( tmpFile, bytes );

    return tmpFile;
}
See Also