Notes to Callers
Below are the examples for setting a FileProvider parameter/property.
This property can be set to:
The document viewer only needs a readable file provider as it only calls GetInfo and OpenRead.
public FileProvider Document { get; set; }
Public Property Document As FileProvider
Get
Set
For generating the cache key, to uniquely identify a document file, we use a string combination of file extension, file size and file date, this way cache collisions do not occur and we can reuse the cached file even if the file name before extension is changed (file1.docx and file2.docx have same cache key because it's still the same document according to file extension, file size and file date).
File providers like FileSystemFileProvider (a file on disk, on Amazon S3, on Azure) can provide file size and file date automatically however some file providers will not have this knowledge, e.g.StreamFileProvider, MemoryFileProvider (how could they know date modified of your data in a byte array or a stream?).
So for this purpose, these kind of providers have an additional property or constructor argument named DateModified and/or Size. You need to specify these to ensure you uniquely identify a document.
Setting document in code:
//Setting a physical/virtual path string:
//These strings are parsed as a FileSystemFileProvider instance with a PhysicalLocation instance.
documentViewer.Document = @"c:\SomeFolder\Document.docx";
//Note that virtual paths can only be resolved in a web application.
//and on Linux paths starting with "/" are physical paths and not virtual paths.
documentViewer.Document = "/SomeFolder/Document.docx";
documentViewer.Document = "~/SomeFolder/Document.docx"; //"~" means relative to web application root.
//Setting a URL or a Data URL string:
//Strings starting with "http://" or "https://" are parsed as a UrlFileProvider instance.
//Strings starting with "data:" are parsed as a DataUrlFileProvider instance.
documentViewer.Document = "http://example.com/SomeFolder/Document.docx";
documentViewer.Document = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
//Setting a MemoryFileProvider instance,
//to connect to a file in a byte array (byte[]) or a MemoryStream:
//Optional parameter dateModified: used for detailed file info, e.g. for generating better cache keys.
documentViewer.Document = new MemoryFileProvider(
"Document.docx", //file can also be set as a relative path "SomeFolder/Document.docx".
yourByteArray,
yourFileDateModified //Provide dateModified to prevent cache key conflicts.
);
documentViewer.Document = new MemoryFileProvider(
"Document.docx", //file can also be set as a relative path "SomeFolder/Document.docx".
yourMemoryStream,
yourFileDateModified //Provide dateModified to prevent cache key conflicts.
);
//Setting a StreamFileProvider instance,
//to connect to a file in a Stream:
//Optional parameters dateModified and size: used for detailed file info, e.g. for generating better cache keys.
documentViewer.Document = new StreamFileProvider(
"Document.docx", //file can also be set as a relative path "SomeFolder/Document.docx".
yourStream,
yourFileDateModified, //Provide dateModified to prevent cache key conflicts.
yourFileSize //Provide size only if your stream is not seekable to prevent cache key conflicts.
);
//Setting a FileSystemFileProvider instance with a PhysicalLocation instance,
//to connect as a specific Windows user to a UNC path or a protected local path:
//UserName can be specified as "Domain\User", "User@Domain" (UPN format), "Machine\User", "User" (local user).
documentViewer.Document = new FileSystemFileProvider
{
File = "Document.docx",
Location = new PhysicalLocation
{
Path = @"\\server\share", //Path can be a UNC path or a local path
UserName = "USERNAME",
Password = "PASSWORD"
}
};
//Setting a FileSystemFileProvider instance with an AzureBlobLocation instance,
//to connect to Azure Blob cloud file system.
documentViewer.Document = new FileSystemFileProvider
{
File = "Document.docx",
Location = new AzureBlobLocation
{
//Leave Path empty to connect to the root of the container.
//For connecting to subfolders, Path should be specified as a relative path (eg. "some/folder")
//Path = "some/folder",
//Get these values from your Azure Portal (Storage Account -> Access Keys -> Connection String)
Container = "CONTAINER",
AccountName = "XXX",
AccountKey = "XXX"
}
};
//Setting a FileSystemFileProvider instance with an AmazonS3Location instance,
//to connect to Amazon S3 cloud file system.
documentViewer.Document = new FileSystemFileProvider
{
File = "Document.docx",
Location = new AmazonS3Location
{
//Leave Path empty to connect to the root of the bucket.
//For connecting to subfolders, Path should be specified as a relative path (eg. "some/folder")
//Path = "some/folder",
BucketName = "BUCKET",
Region = "eu-central-1",
AccessKeyId = "XXX",
SecretAccessKey = "XXX",
}
};
//Setting a DatabaseFileProvider instance,
//to connect to a database file system.
documentViewer.Document = new DatabaseFileProvider
{
File = "Document.docx", //File can also be set as a relative path "SomeFolder/Document.docx".
ConnectionString = "Data Source=(local); Initial Catalog=SomeDb; Integrated Security=SSPI",
//ProviderName = "System.Data.SqlClient" //ProviderName default value is "System.Data.SqlClient"
Table = "SomeTable", //Table default value is "File".
//Mandatory fields:
KeyField = "Path", //KeyField default value is "Id".
ContentField = "Content", //ContentField default value is "Content".
//Optional fields DateModifiedField and SizeField: used for detailed file info, e.g. for generating better cache keys.
//NameField = "Name", //NameField used for overriding file name specified in File.
DateModifiedField = "DateModified", //Provide DateModifiedField to prevent cache key conflicts.
SizeField = "Size" //Provide SizeField to prevent cache key conflicts.
};
//Setting a file provider string (can be useful when you need to set a file provider in a string environment e.g. ASPX markup):
//See below for other provider string examples (UNC Path, AmazonS3, AzureBlob, Database etc.).
documentViewer.Document = @"Type=FileSystem; File=Document.docx; Location='Type=Physical; Path=c:\SomeFolder'";
//See below for other builtin file provider examples (AssemblyResourceFileProvider, TemporaryFileProvider) etc.)
//and a custom file provider implementation.
'Setting a physical/virtual path string:
'These strings are parsed as a FileSystemFileProvider instance with a PhysicalLocation instance.
documentViewer.Document = "c:\SomeFolder\Document.docx"
'Note that virtual paths can only be resolved in a web application.
'and on Linux paths starting with "/" are physical paths and not virtual paths.
documentViewer.Document = "/SomeFolder/Document.docx"
'"~" means relative to web application root.
documentViewer.Document = "~/SomeFolder/Document.docx"
'Setting a URL or a Data URL string:
'Strings starting with "http://" or "https://" are parsed as a UrlFileProvider instance.
'Strings starting with "data:" are parsed as a DataUrlFileProvider instance.
documentViewer.Document = "http://example.com/SomeFolder/Document.docx"
documentViewer.Document = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
'Setting a MemoryFileProvider instance,
'to connect to a file in a byte array (byte[]) or a MemoryStream:
'Optional parameter dateModified: used for detailed file info, e.g. for generating better cache keys.
documentViewer.Document = New MemoryFileProvider(
"Document.docx", 'file can also be set as a relative path "SomeFolder/Document.docx".
yourByteArray,
yourFileDateModified 'Provide dateModified to prevent cache key conflicts.
)
documentViewer.Document = New MemoryFileProvider(
"Document.docx", 'file can also be set as a relative path "SomeFolder/Document.docx".
yourMemoryStream,
yourFileDateModified 'Provide dateModified to prevent cache key conflicts.
)
'Setting a StreamFileProvider instance,
'to connect to a file in a Stream:
'Optional parameters dateModified and size: used for detailed file info, e.g. for generating better cache keys.
documentViewer.Document = New StreamFileProvider(
"Document.docx", 'file can also be set as a relative path "SomeFolder/Document.docx".
yourStream,
yourFileDateModified, 'Provide dateModified to prevent cache key conflicts.
yourFileSize 'Provide size only if your stream is not seekable to prevent cache key conflicts.
)
'Setting a FileSystemFileProvider instance with a PhysicalLocation instance,
'to connect as a specific Windows user to a UNC path or a protected local path:
'UserName can be specified as "Domain\User", "User@Domain" (UPN format), "Machine\User", "User" (local user).
documentViewer.Document = New FileSystemFileProvider() With {
.File = "Document.docx",
.Location = New PhysicalLocation() With {
.Path = "\\server\share", 'Path can be a UNC path or a local path
.UserName = "USERNAME",
.Password = "PASSWORD"
}
}
'Setting a FileSystemFileProvider instance with an AzureBlobLocation instance,
'to connect to Azure Blob cloud file system.
'Leave Path empty to connect to the root of the container.
'For connecting to subfolders, Path should be specified as a relative path (eg. "some/folder")
'Path = "some/folder",
'Get these values from your Azure Portal (Storage Account -> Access Keys -> Connection String)
documentViewer.Document = New FileSystemFileProvider() With {
.File = "Document.docx",
.Location = New AzureBlobLocation() With {
.Container = "CONTAINER",
.AccountName = "XXX",
.AccountKey = "XXX"
}
}
'Setting a FileSystemFileProvider instance with an AmazonS3Location instance,
'to connect to Amazon S3 cloud file system.
'Leave Path empty to connect to the root of the bucket.
'For connecting to subfolders, Path should be specified as a relative path (eg. "some/folder")
'Path = "some/folder",
documentViewer.Document = New FileSystemFileProvider() With {
.File = "Document.docx",
.Location = New AmazonS3Location() With {
.BucketName = "BUCKET",
.Region = "eu-central-1",
.AccessKeyId = "XXX",
.SecretAccessKey = "XXX"
}
}
'Setting a DatabaseFileProvider instance,
'to connect to a database file system.
'Mandatory fields are KeyField and ContentField.
'Optional fields DateModifiedField and SizeField: used for detailed file info, e.g. for generating better cache keys.
documentViewer.Document = New DatabaseFileProvider() With {
.File = "Document.docx", 'File can also be set as a relative path "SomeFolder/Document.docx".
.ConnectionString = "Data Source=(local); Initial Catalog=SomeDb; Integrated Security=SSPI",
.ProviderName = "System.Data.SqlClient", 'ProviderName default value is "System.Data.SqlClient"
.Table = "SomeTable", 'Table default value is "File".
.KeyField = "Path", 'KeyField default value is "Id".
.ContentField = "Content", 'ContentField default value is "Content".
.NameField = "Name", 'NameField used for overriding file name specified in File (optional).
.DateModifiedField = "DateModified", 'Provide DateModifiedField to prevent cache key conflicts.
.SizeField = "Size" 'Provide SizeField to prevent cache key conflicts.
}
'Setting a file provider string (can be useful when you need to set a file provider in a string environment e.g. ASPX markup):
'See below for other provider string examples (UNC Path, AmazonS3, AzureBlob, Database etc.).
documentViewer.Document = "Type=FileSystem; File=Document.docx; Location='Type=Physical; Path=c:\SomeFolder'"
'See below for other builtin file provider examples (AssemblyResourceFileProvider, TemporaryFileProvider) etc.)
'and a custom file provider implementation.
Setting document in ASPX markup:
<%--
Setting a physical path string:
See below for other path string examples.
--%>
<GleamTech:DocumentViewerControl runat="server"
Width="800"
Height="600"
Document="c:\SomeFolder\Document.docx" />
<%--
Setting a virtual path string:
See below for other path string examples.
--%>
<GleamTech:DocumentViewerControl runat="server"
Width="800"
Height="600"
Document="~/SomeFolder/Document.docx" />
<%--
Setting a URL string:
See below for other path string examples.
--%>
<GleamTech:DocumentViewerControl runat="server"
Width="800"
Height="600"
Document="http://example.com/SomeFolder/Document.docx" />
<%--
Setting a provider string:
See below for other provider string examples.
--%>
<GleamTech:DocumentViewerControl runat="server"
Width="800"
Height="600"
Document="Type=FileSystem; File=Document.docx; Location='Type=Physical; Path=c:\SomeFolder'" />
Setting a plain string:
FileProvider fileProvider;
//Setting a physical/virtual path string:
//These strings are parsed as a FileSystemFileProvider instance with a PhysicalLocation instance.
fileProvider = @"c:\SomeFolder\SomeFile.ext";
//Note that virtual paths can only be resolved in a web application
//and on Linux paths starting with "/" are physical paths and not virtual paths.
fileProvider = "/SomeFolder/SomeFile.ext";
fileProvider = "~/SomeFolder/SomeFile.ext"; //"~" means relative to web application root.
//Setting a URL or a Data URL string:
//Strings starting with "http://" or "https://" are parsed as a UrlFileProvider instance.
//Strings starting with "data:" are parsed as a DataUrlFileProvider instance.
fileProvider = "http://example.com/SomeFolder/SomeFile.ext";
fileProvider = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
Dim fileProvider As FileProvider
'Setting a physical/virtual path string:
'These strings are parsed as a FileSystemFileProvider instance with a PhysicalLocation instance.
fileProvider = "c:\SomeFolder\SomeFile.ext"
'Note that virtual paths can only be resolved in a web application
'and on Linux paths starting with "/" are physical paths and not virtual paths.
'"~" means relative to web application root.
fileProvider = "/SomeFolder/SomeFile.ext"
fileProvider = "~/SomeFolder/SomeFile.ext"
'Setting a URL or a Data URL string:
'Strings starting with "http://" or "https://" are parsed as a UrlFileProvider instance.
'Strings starting with "data:" are parsed as a DataUrlFileProvider instance.
fileProvider = "http://example.com/SomeFolder/SomeFile.ext"
fileProvider = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
Setting a MemoryFileProvider instance, to connect to a file in a byte array (byte) or a MemoryStream:
FileProvider fileProvider;
//Setting a MemoryFileProvider instance,
//to connect to a file in a byte array (byte[]) or a MemoryStream:
//Optional parameter dateModified: used for detailed file info, e.g. for generating better cache keys.
fileProvider = new MemoryFileProvider(
"SomeFile.ext", //file can also be set as a relative path "SomeFolder/SomeFile.ext".
yourByteArray,
yourFileDateModified //Provide dateModified to prevent cache key conflicts.
);
fileProvider = new MemoryFileProvider(
"SomeFile.ext", //file can also be set as a relative path "SomeFolder/SomeFile.ext".
yourMemoryStream,
yourFileDateModified //Provide dateModified to prevent cache key conflicts.
);
//Create with empty MemoryStream
//Note that this instance should be written (filled with data via OpenWrite method) before being read
fileProvider = new MemoryFileProvider("SomeFolder/SomeFile.ext");
Dim fileProvider As FileProvider
'Setting a MemoryFileProvider instance,
'to connect to a file in a byte array (byte[]) or a MemoryStream:
'Optional parameter dateModified: used for detailed file info, e.g. for generating better cache keys.
fileProvider = New MemoryFileProvider(
"SomeFile.ext", 'file can also be set as a relative path "SomeFolder/SomeFile.ext".
yourByteArray,
yourFileDateModified 'Provide dateModified to prevent cache key conflicts.
)
fileProvider = New MemoryFileProvider(
"SomeFile.ext", 'file can also be set as a relative path "SomeFolder/SomeFile.ext".
yourMemoryStream,
yourFileDateModified 'Provide dateModified to prevent cache key conflicts.
)
'Create with empty MemoryStream
'Note that this instance should be written (filled with data via OpenWrite method) before being read
fileProvider = New MemoryFileProvider("SomeFolder/SomeFile.ext")
Setting a StreamFileProvider instance, to connect to a file in a Stream:
FileProvider fileProvider;
//Setting a StreamFileProvider instance,
//to connect to a file in a Stream:
//Optional parameters dateModified and size: used for detailed file info, e.g. for generating better cache keys.
fileProvider = new StreamFileProvider(
"SomeFile.ext", //file can also be set as a relative path "SomeFolder/SomeFile.ext".
yourStream,
yourFileDateModified, //Provide dateModified to prevent cache key conflicts.
yourFileSize //Provide size only if your stream is not seekable to prevent cache key conflicts.
);
Dim fileProvider As FileProvider
'Setting a StreamFileProvider instance,
'to connect to a file in a Stream:
'Optional parameters dateModified and size: used for detailed file info, e.g. for generating better cache keys.
fileProvider = New StreamFileProvider(
"SomeFile.ext", 'file can also be set as a relative path "SomeFolder/SomeFile.ext".
yourStream,
yourFileDateModified, 'Provide dateModified to prevent cache key conflicts.
yourFileSize 'Provide size only if your stream is not seekable to prevent cache key conflicts.
)
Setting a FileSystemFileProvider instance with a PhysicalLocation instance, to connect to physical file system:
FileProvider fileProvider;
//Setting a physical file provider via a FileSystemFileProvider instance:
fileProvider = new FileSystemFileProvider
{
File = "SomeFile.ext",
Location = new PhysicalLocation
{
//Path can also be virtual path string like "~/SomeFolder" in a web application.
Path = @"c:\SomeFolder"
}
};
//Setting a physical file provider via a provider string (same as above):
//In a provider string, if a value contains semi-colon character, that value should be enclosed
//in single quotes (eg. Password='PASS;WORD') or double quotes (eg. Password="PASS;WORD").
fileProvider = @"Type=FileSystem; File=SomeFile.ext; Location='Type=Physical; Path=c:\SomeFolder'";
//---------------------------------------
//Setting a FileSystemFileProvider instance with a PhysicalLocation instance,
//to connect as a specific Windows user to a UNC path or a protected local path:
//UserName can be specified as "Domain\User", "User@Domain" (UPN format), "Machine\User", "User" (local user).
fileProvider = new FileSystemFileProvider
{
File = "SomeFile.ext",
Location = new PhysicalLocation
{
Path = @"\\server\share", //Path can be a UNC path or a local path
UserName = "USERNAME",
Password = "PASSWORD"
}
};
//Setting a physical file provider via a provider string, to connect as a specific user (same as above):
//In a provider string, if a value contains semi-colon character, that value should be enclosed
//in single quotes (eg. Password='PASS;WORD') or double quotes (eg. Password="PASS;WORD").
fileProvider = @"Type=FileSystem; File=SomeFile.ext; Location='Path=\\server\share; User Name=USERNAME; Password=PASSWORD'";
//---------------------------------------
//Setting a physical file provider via a FileSystemFileProvider instance, to connect as the authenticated user:
//If Windows Authentication is used in IIS for this site, location can be specified like this
//to connect as the already authenticated user:
fileProvider = new FileSystemFileProvider
{
File = "SomeFile.ext",
Location = new PhysicalLocation
{
Path = @"\\server\share", //Path can be a UNC path or a local path
AuthenticatedUser = AuthenticatedUser.Windows
}
};
//Setting a physical file provider via a provider string, to connect as the authenticated user:
fileProvider = @"Type=FileSystem; File=SomeFile.ext; Location='Path=\\server\share; Authenticated User=Windows'";
Dim fileProvider As FileProvider
'Setting a physical file provider via a FileSystemFileProvider instance:
'Path can also be virtual path string like "~/SomeFolder" in a web application.
fileProvider = New FileSystemFileProvider() With {
.File = "SomeFile.ext",
.Location = New PhysicalLocation() With {
.Path = "c:\SomeFolder"
}
}
'Setting a physical file provider via a provider string (same as above):
'In a provider string, if a value contains semi-colon character, that value should be enclosed
'in single quotes (eg. Password='PASS;WORD') or double quotes (eg. Password="PASS;WORD").
fileProvider = "Type=FileSystem; File=SomeFile.ext; Location='Type=Physical; Path=c:\SomeFolder'"
'---------------------------------------
'Setting a FileSystemFileProvider instance with a PhysicalLocation instance,
'to connect as a specific Windows user to a UNC path or a protected local path:
'UserName can be specified as "Domain\User", "User@Domain" (UPN format), "Machine\User", "User" (local user).
fileProvider = New FileSystemFileProvider() With {
.File = "SomeFile.ext",
.Location = New PhysicalLocation() With {
.Path = "\\server\share", 'Path can be a UNC path or a local path
.UserName = "USERNAME",
.Password = "PASSWORD"
}
}
'Setting a physical file provider via a provider string, to connect as a specific user (same as above):
'In a provider string, if a value contains semi-colon character, that value should be enclosed
'in single quotes (eg. Password='PASS;WORD') or double quotes (eg. Password="PASS;WORD").
fileProvider = "Type=FileSystem; File=SomeFile.ext; Location='Path=\\server\share; User Name=USERNAME; Password=PASSWORD'"
'---------------------------------------
'Setting a physical file provider via a FileSystemFileProvider instance, to connect as the authenticated user:
'If Windows Authentication is used in IIS for this site, location can be specified like this
'to connect as the already authenticated user:
fileProvider = New FileSystemFileProvider() With {
.File = "SomeFile.ext",
.Location = New PhysicalLocation() With {
.Path = "\\server\share", 'Path can be a UNC path or a local path
.AuthenticatedUser = AuthenticatedUser.Windows
}
}
'Setting a physical file provider via a provider string, to connect as the authenticated user:
fileProvider = "Type=FileSystem; File=SomeFile.ext; Location='Path=\\server\share; Authenticated User=Windows'"
Setting a FileSystemFileProvider instance with an AzureBlobLocation instance, to connect to Azure Blob cloud file system:
FileProvider fileProvider;
//Setting a FileSystemFileProvider instance with an AzureBlobLocation instance,
//to connect to Azure Blob cloud file system.
fileProvider = new FileSystemFileProvider
{
File = "SomeFile.ext",
Location = new AzureBlobLocation
{
//Leave Path empty to connect to the root of the container.
//For connecting to subfolders, Path should be specified as a relative path (eg. "some/folder")
//Path = "some/folder",
//Get these values from your Azure Portal (Storage Account -> Access Keys -> Connection String)
Container = "CONTAINER",
AccountName = "XXX",
AccountKey = "XXX"
}
};
//Setting a an Azure Blob file provider via a provider string (same as above):
//In a provider string, if a value contains semi-colon character, that value should be enclosed
//in single quotes (eg. Password='PASS;WORD') or double quotes (eg. Password="PASS;WORD").
fileProvider = @"Type=FileSystem; File=SomeFile.ext; Location='Type=AzureBlob; Container=CONTAINER; Account Name=XXX; Account Key=XXX'";
Dim fileProvider As FileProvider
'Setting a FileSystemFileProvider instance with an AzureBlobLocation instance,
'to connect to Azure Blob cloud file system.
'Leave Path empty to connect to the root of the container.
'For connecting to subfolders, Path should be specified as a relative path (eg. "some/folder")
'Path = "some/folder",
'Get these values from your Azure Portal (Storage Account -> Access Keys -> Connection String)
fileProvider = New FileSystemFileProvider() With {
.File = "SomeFile.ext",
.Location = New AzureBlobLocation() With {
.Container = "CONTAINER",
.AccountName = "XXX",
.AccountKey = "XXX"
}
}
'Setting a an Azure Blob file provider via a provider string (same as above):
'In a provider string, if a value contains semi-colon character, that value should be enclosed
'in single quotes (eg. Password='PASS;WORD') or double quotes (eg. Password="PASS;WORD").
fileProvider = "Type=FileSystem; File=SomeFile.ext; Location='Type=AzureBlob; Container=CONTAINER; Account Name=XXX; Account Key=XXX'"
Setting a FileSystemFileProvider instance with an AmazonS3Location instance, to connect to Amazon S3 cloud file system:
FileProvider fileProvider;
//Setting a FileSystemFileProvider instance with an AmazonS3Location instance,
//to connect to Amazon S3 cloud file system.
fileProvider = new FileSystemFileProvider
{
File = "SomeFile.ext",
Location = new AmazonS3Location
{
//Leave Path empty to connect to the root of the bucket.
//For connecting to subfolders, Path should be specified as a relative path (eg. "some/folder")
//Path = "some/folder",
BucketName = "BUCKET",
Region = "eu-central-1",
AccessKeyId = "XXX",
SecretAccessKey = "XXX",
}
};
//Setting an Amazon S3 file provider via a provider string (same as above):
//In a provider string, if a value contains semi-colon character, that value should be enclosed
//in single quotes (eg. Password='PASS;WORD') or double quotes (eg. Password="PASS;WORD").
fileProvider = @"Type=FileSystem; File=SomeFile.ext; Location='Type=AmazonS3; Bucket Name=BUCKET; Region=eu-central-1; Access Key Id=XXX; Secret Access Key=XXX'";
Dim fileProvider As FileProvider
'Setting a FileSystemFileProvider instance with an AmazonS3Location instance,
'to connect to Amazon S3 cloud file system.
'Leave Path empty to connect to the root of the bucket.
'For connecting to subfolders, Path should be specified as a relative path (eg. "some/folder")
'Path = "some/folder",
fileProvider = New FileSystemFileProvider() With {
.File = "SomeFile.ext",
.Location = New AmazonS3Location() With {
.BucketName = "BUCKET",
.Region = "eu-central-1",
.AccessKeyId = "XXX",
.SecretAccessKey = "XXX"
}
}
'Setting an Amazon S3 file provider via a provider string (same as above):
'In a provider string, if a value contains semi-colon character, that value should be enclosed
'in single quotes (eg. Password='PASS;WORD') or double quotes (eg. Password="PASS;WORD").
fileProvider = "Type=FileSystem; File=SomeFile.ext; Location='Type=AmazonS3; Bucket Name=BUCKET; Region=eu-central-1; Access Key Id=XXX; Secret Access Key=XXX'"
Setting a UrlFileProvider instance, to connect to a file located at a URL:
FileProvider fileProvider;
//Setting a URL file provider via a UrlFileProvider instance:
//File should start with "http://" or "https://".
fileProvider = new UrlFileProvider
{
File = "http://example.com/SomeFolder/SomeFile.ext"
};
//Setting a URL file provider via a provider string (same as above):
fileProvider = "Type=Url; File=http://example.com/SomeFolder/SomeFile.ext";
Dim fileProvider As FileProvider
'Setting a URL file provider via a UrlFileProvider instance:
'File should start with "http://" or "https://".
fileProvider = New UrlFileProvider() With {
.File = "http://example.com/SomeFolder/SomeFile.ext"
}
'Setting a URL file provider via a provider string (same as above):
fileProvider = "Type=Url; File=http://example.com/SomeFolder/SomeFile.ext"
Setting a DataUrlFileProvider instance, to connect to a file encoded in a Data URL:
FileProvider fileProvider;
//Setting a Data URL file provider via a UrlFileProvider instance:
//File should start with "data:".
fileProvider = new DataUrlFileProvider
{
File = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
};
//Setting a Data URL file provider via a provider string (same as above):
fileProvider = "Type=DataUrl; File='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'";
Dim fileProvider As FileProvider
'Setting a Data URL file provider via a UrlFileProvider instance:
'File should start with "data:".
fileProvider = New DataUrlFileProvider() With {
.File = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
}
'Setting a Data URL file provider via a provider string (same as above):
fileProvider = "Type=DataUrl; File='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'"
Setting a DatabaseFileProvider instance, to connect to a database file system:
FileProvider fileProvider;
//Setting a DatabaseFileProvider instance,
//to connect to a database file system.
fileProvider = new DatabaseFileProvider
{
File = "SomeFile.ext", //File can also be set as a relative path "SomeFolder/SomeFile.ext".
ConnectionString = "Data Source=(local); Initial Catalog=SomeDb; Integrated Security=SSPI",
//ProviderName = "System.Data.SqlClient" //ProviderName default value is "System.Data.SqlClient"
Table = "SomeTable", //Table default value is "File".
//Mandatory fields:
KeyField = "Path", //KeyField default value is "Id".
ContentField = "Content", //ContentField default value is "Content".
//Optional fields DateModifiedField and SizeField: used for detailed file info, e.g. for generating better cache keys.
//NameField = "Name", //NameField used for overriding file name specified in File.
DateModifiedField = "DateModified", //Provide DateModifiedField to prevent cache key conflicts.
SizeField = "Size" //Provide SizeField to prevent cache key conflicts.
};
//Setting a database file provider via a provider string (same as above):
//In a provider string, if a value contains semi-colon character, that value should be enclosed
//in single quotes (eg. Password='PASS;WORD') or double quotes (eg. Password="PASS;WORD").
fileProvider = "Type=Database; File=SomeFolder/SomeFile.ext; Connection String='Data Source=(local); Initial Catalog=SomeDb; Integrated Security=SSPI'; Table=SomeTable; Key Field=Path; Content Field=Content";
//---------------------------------------
/*
Sample SQL script to create a table in the database:
CREATE TABLE [File] (
[Id] [int] IDENTITY(1, 1) PRIMARY KEY,
[Path] [nvarchar](500) NOT NULL UNIQUE,
[Name] [nvarchar](100),
[DateModified] [smalldatetime],
[Size] [bigint],
[Content] [varbinary](max)
);
*
*/
Dim fileProvider As FileProvider
'Setting a DatabaseFileProvider instance,
'to connect to a database file system.
'Mandatory fields are KeyField and ContentField.
'Optional fields DateModifiedField and SizeField: used for detailed file info, e.g. for generating better cache keys.
fileProvider = New DatabaseFileProvider() With {
.File = "SomeFile.ext", 'File can also be set as a relative path "SomeFolder/SomeFile.ext".
.ConnectionString = "Data Source=(local); Initial Catalog=SomeDb; Integrated Security=SSPI",
.ProviderName = "System.Data.SqlClient", 'ProviderName default value is "System.Data.SqlClient"
.Table = "SomeTable", 'Table default value is "File".
.KeyField = "Path", 'KeyField default value is "Id".
.ContentField = "Content", 'ContentField default value is "Content".
.NameField = "Name", 'NameField used for overriding file name specified in File (optional).
.DateModifiedField = "DateModified", 'Provide DateModifiedField to prevent cache key conflicts.
.SizeField = "Size" 'Provide SizeField to prevent cache key conflicts.
}
'Setting a database file provider via a provider string (same as above):
'In a provider string, if a value contains semi-colon character, that value should be enclosed
'in single quotes (eg. Password='PASS;WORD') or double quotes (eg. Password="PASS;WORD").
fileProvider = "Type=Database; File=SomeFolder/SomeFile.ext; Connection String='Data Source=(local); Initial Catalog=SomeDb; Integrated Security=SSPI'; Table=SomeTable; Key Field=Path; Content Field=Content"
'---------------------------------------
' Sample SQL script to create a table in the database:
'
' CREATE TABLE [File] (
' [Id] [int] IDENTITY(1, 1) PRIMARY KEY,
' [Path] [nvarchar](500) NOT NULL UNIQUE,
' [Name] [nvarchar](100),
' [DateModified] [smalldatetime],
' [Size] [bigint],
' [Content] [varbinary](max)
' );
Setting a AssemblyResourceFileProvider instance, to connect to a file embedded in an assembly:
FileProvider fileProvider;
//Setting an assembly resource file provider via a AssemblyResourceFileProvider instance:
fileProvider = new AssemblyResourceFileProvider
{
File = @"SomeFolder\SomeFile.ext",
Assembly = typeof(SomeType).Assembly,
BaseNamespace = typeof(SomeType).Namespace
};
//Setting an assembly file provider via a provider string (same as above):
fileProvider = @"Type=AssemblyResource; File=SomeFolder\SomeFile.ext; Assembly=SomeAssembly; Base Namespace=Some.Namespace";
Dim fileProvider As FileProvider
'Setting an assembly resource file provider via a AssemblyResourceFileProvider instance:
fileProvider = New AssemblyResourceFileProvider() With {
.File = "SomeFolder\SomeFile.ext",
.Assembly = GetType(SomeType).Assembly,
.BaseNamespace = GetType(SomeType).[Namespace]
}
'Setting an assembly file provider via a provider string (same as above):
fileProvider = "Type=AssemblyResource; File=SomeFolder\SomeFile.ext; Assembly=SomeAssembly; Base Namespace=Some.Namespace"
Setting a TemporaryFileProvider instance, to connect to a temporary file:
FileProvider fileProvider;
//Setting a temporary file provider via a TemporaryFileProvider instance:
//Note that this instance should be written (filled with data via OpenWrite method) before being read
fileProvider = new TemporaryFileProvider("SomeFolder/SomeFile.ext");
Dim fileProvider As FileProvider
'Setting a temporary file provider via a TemporaryFileProvider instance:
'Note that this instance should be written (filled with data via OpenWrite method) before being read
fileProvider = New TemporaryFileProvider("SomeFolder/SomeFile.ext")
Setting and implementing a custom file provider:
FileProvider fileProvider;
//Setting a custom file provider:
fileProvider = new CustomFileProvider
{
File = @"SomeFolder\SomeFile.ext",
Parameters = new Dictionary<string, string>
{
{"parameter1", "value1"}
}
};
Dim fileProvider As FileProvider
'Setting a custom file provider:
fileProvider = New CustomFileProvider() With {
.File = "SomeFolder\SomeFile.ext",
.Parameters = New Dictionary(Of String, String)() From {
{"parameter1", "value1"}
}
}
public class CustomFileProvider : FileProvider
{
public override string File { get; set; }
//Return true if DoGetInfo method is implemented, and false if not.
public override bool CanGetInfo => true;
//Return true if DoOpenRead method is implemented, and false if not.
public override bool CanOpenRead => true;
//Return true if DoOpenWrite method is implemented, and false if not.
public override bool CanOpenWrite => false;
//Return true only if File identifier is usable across processes/machines.
public override bool CanSerialize => false;
protected override FileProviderInfo DoGetInfo()
{
//Return info here which corresponds to the identifier in File property.
//When this file provider is used in DocumentViewer:
//This method will be called every time DocumentViewer requests a document.
//The cache key and document format will be determined according to the info you return here.
string fileName = File;
DateTime dateModified = DateTime.Now;
long size = 81920;
return new FileProviderInfo(fileName, dateModified, size);
//throw new NotImplementedException();
}
protected override Stream DoOpenRead()
{
//Open and return a readable stream here which corresponds to the identifier in File property.
//You can make use of Parameters dictionary which was passed when this provider was initialized.
//var someParameter = Parameters["parameter1"];
//When this file provider is used in DocumentViewer:
//This method will be called only when original input document is required,
//For example if DocumentViewer already did the required conversions and cached the results,
//it will not be called.
return readableStream;
//throw new NotImplementedException();
}
protected override Stream DoOpenWrite()
{
//Open and return a writable stream here which corresponds to the identifier in File property.
throw new NotImplementedException();
}
}
Public Class CustomFileProvider
Inherits FileProvider
Public Overrides Property File As String
'Return true if DoGetInfo method is implemented, and false if not.
Public Overrides ReadOnly Property CanGetInfo As Boolean = true
'Return true if DoOpenRead method is implemented, and false if not.
Public Overrides ReadOnly Property CanOpenRead As Boolean = true
'Return true if DoOpenWrite method is implemented, and false if not.
Public Overrides ReadOnly Property CanOpenWrite As Boolean = false
'Return true only if File identifier is usable across processes/machines.
Public Overrides ReadOnly Property CanSerialize As Boolean = false
Protected Overrides Function DoGetInfo() As FileProviderInfo
'Return info here which corresponds to the identifier in File property.
'When this file provider is used in DocumentViewer:
'This method will be called every time DocumentViewer requests a document.
'The cache key and document format will be determined according to the info you return here.
Dim fileName As String = File
Dim dateModified As DateTime = DateTime.Now
Dim size As Long = 81920
Return New FileProviderInfo(fileName, dateModified, size)
'throw new NotImplementedException();
End Function
Protected Overrides Function DoOpenRead() As Stream
'Open and return a readable stream here which corresponds to the identifier in File property.
'You can make use of Parameters dictionary which was passed when this provider was initialized.
'var someParameter = Parameters["parameter1"];
'When this file provider is used in DocumentViewer:
'This method will be called only when original input document is required,
'For example if DocumentViewer already did the required conversions and cached the results,
'it will not be called.
Return readableStream
'throw new NotImplementedException();
End Function
Protected Overrides Function DoOpenWrite() As Stream
'Open and return a writable stream here which corresponds to the identifier in File property.
Throw New NotImplementedException()
End Function
End Class