Table of Contents

Class NetworkFileProvider

Namespace
combit.Reporting.DataProviders
Assembly
combit.ListLabel31.CrossPlatform.dll

Provides methods for reading files or downloading content from a URL. Supports both local file access and HTTP(S) requests with optional Windows or basic authentication.

public class NetworkFileProvider
Inheritance
NetworkFileProvider
Inherited Members

Properties

AcceptHeader

Gets or sets the value for the Accept header used in HTTP requests.

public string AcceptHeader { get; set; }

Property Value

string

HttpMethod

Gets or sets the HTTP method used when making web requests. The default value is "GET".

public string HttpMethod { get; set; }

Property Value

string

Password

Gets or sets the secure password for authentication.

public SecureString Password { get; set; }

Property Value

SecureString

Timeout

Gets or sets the timeout duration for network operations. The default value is 10 seconds.

public TimeSpan Timeout { get; set; }

Property Value

TimeSpan

UseWindowsAuthentication

Gets or sets a value indicating whether to use Windows Authentication for HTTP requests. When true, default Windows credentials are used.

public bool UseWindowsAuthentication { get; set; }

Property Value

bool

UserName

Gets or sets the user name for authentication when accessing network resources.

public string UserName { get; set; }

Property Value

string

Methods

DownloadFromUrl(Uri)

Downloads content from the specified URL using an HttpClient.

protected virtual string DownloadFromUrl(Uri url)

Parameters

url Uri

The URL to download content from.

Returns

string

The content downloaded from the URL as a string.

Remarks

This method configures an HttpClientHandler to use either default Windows credentials or specified credentials if UseWindowsAuthentication is true or UserName is provided. It also sets automatic redirection and decompression.

ReadAsString(string)

Reads content from a local file or a URL as a string. If the specified path or URL represents a file, its content is read from disk. Otherwise, the content is downloaded from the network.

public string ReadAsString(string filePathOrUrl)

Parameters

filePathOrUrl string

The file path or URL of the resource.

Returns

string

The content of the file or web resource as a string.

Exceptions

ArgumentNullException

Thrown if filePathOrUrl is null.

ReadFile(string, bool)

Reads the content of a local file as a string.

protected virtual string ReadFile(string filePath, bool isUncPath)

Parameters

filePath string

The file path to read from.

isUncPath bool

Indicates whether the file path is a UNC path.

Returns

string

The file content as a string.

Remarks

If no UserName is provided, the file is read directly. Otherwise, impersonation is used to access the file. In .NET Core, WindowsIdentity.RunImpersonated is used; in other frameworks, a custom impersonation context is used.