Skip to content

NSG.Library.Helpers

Phil Huhn edited this page Apr 27, 2018 · 5 revisions

NSG.Library.Helpers is a collection of support helper (static) methods. The helper methods are in three classes as follows:

  • App setting configuration retrieval (Config),
  • Files and file system utilities (Files),
  • Operation system (OS) command execution (OS).

Table of Contents

Config (NSG.Library.Helpers.Config)

Static helpers for handling AppSettings configuration.

GetStringAppSettingConfigValue(System.String,System.String)

Get a value from the AppSetting section of the web config.

Parameters

configAppKey

AppSetting key value

defaultValue

if not found return this value

Return Value

string of the value in the appSetting section in the config file.


GetBoolAppSettingConfigValue(System.String,System.Boolean)

Get a value from the AppSetting section of the web config.

Parameters

configAppKey

AppSetting key value

defaultValue

if not found return this boolean value

Return Value

boolean value in the appSetting section in the config file.


GetIntAppSettingConfigValue(System.String,System.Int32)

Get a value from the AppSetting section of the web config.

Parameters

configAppKey

AppSetting key value

defaultValue

if not found return this integer value

Return Value

integer value in the appSetting section in the config file.


Class: Files

 Static helpers for handling files.

Files.TempFileName(System.String,System.String)

 Create a temporary file name.

Parameters

prefix

first part of file name

file 'prefix' examples:
  • tmp
  • ni (as in app initials)
  • nsg (as in company initials)

Parameters

extent

the temporary file name extension:

 ====== file 'extent' examples: ======
 * txt
 * tmp
 * log

Return Value

 string of prefix followed by GUID and extent

Files.DeleteFile(System.String)

            Delete the file

Parameters

fullFilePathAndName

full path and file name


Files.MakeDirectory(System.String)

            Make a directory

Parameters

directoryName

name of the new direcory


Files.FileToByteArray(System.String)

            Read a file into a in-memory byte array.

Parameters

filePath

full path and file name

Return Value

byte array


Files.ByteArrayToFile(System.Byte[],System.String)

            Write a file from an in-memory a byte array.

Parameters

file

byte array

Parameters

fullFileName

full path and file name


Files.FileNameCleaner(System.String)

Remove the following reserved characters and replace with a space.

 *   (less than)
 * > (greater than)
 *  : (colon)
 *  " (double quote)
 *  / (forward slash)
 *             \ (backslash)
 *             | (vertical bar or pipe)
 *             ? (question mark)
 *             * (asterisk)
 *             , (comma)
 *               (amperstand)

Parameters

fileName

file name with out path

Return Value

A clean file name


OS (NSG.Library.Helpers.OS)

Static helpers for handling Operating System interaction.

CallOperatingSystemCmd(System.String,System.String)

Execute the operating system command.

Parameters

cmdStr

The command string to execute in the operating system.

workingDirectory

The base directory to start the OS command.

Return Value

String of the output of the command.

Clone this wiki locally