Tag Archives: snippet

Get value between two strings

You might find this snippet particular useful in cases where you want to get a value between two other values.

This takes advantage of the string’s Split overload to pass an array of two values. This will result in the string being split twice, once for the first value in the array and once more for the second value. The result will be that the second value in the array that Split returns is the actual value between the first and the second value we passed as argument.

Code:

Example:

How to get the short path of a directory

In some occasions it might be necessary to use a directory’s short path. This is possible with the use of the Windows GetShortPathName function.

Implementation:

Simply call the GetShortPath with the directory you want to get the short path as an argument.

Example:

Calculate file checksum

You might have noticed by now that a lot of websites list their files checksum values in their downloads section. Checksums are extremely useful when you want to verify that the file you have downloaded from another source is indeed the same file that is hosted on the official website and that it has not been altered in any way.

For this very reason I’ve put together a method that will generate the checksum of the file of your choice. Simply provide the location of the file and the algorithm you wish to compute the checksum with.

Examples:

Upload file to FTP

This is a simple method that will allow you to upload a file of your choice to an FTP server.

Keep in mind that you will want to do some error catching to ensure that the file exists, the server is responding and so on.

Simply call the method as follows:

Download file from FTP

I’ve created a simple method for you that will download a file from an FTP server and save it in the location you wish.

Keep in mind that ideally you will want to do some error catching for cases that the file does not exist or the server is down and so on.

Simply call the method as follows: