Click or drag to resize

UserResourceGetInputStream Method

Gets a Stream object which can be used to read the contents of the file.

Namespace:  Demo3D.Visuals
Assembly:  Demo3D.Core (in Demo3D.Core.dll) Version: 15.0.2.11458
Syntax
C#
public Stream GetInputStream(
	ScriptContainer script
)

Parameters

script
Type: ScriptContainer
Calling Script

Return Value

Type: Stream
A Stream object which can be used to read the contents of the file.
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