Showing posts with label directory. Show all posts
Showing posts with label directory. Show all posts

Sunday, 27 September 2009

Check if folder exists and return a message in C#

The form I have used for this example contains one label and one button. The code checks the location you specify and then prints a message in the label to tell you if the directory exists.

using System.IO;

private void button1_Click(object sender, EventArgs e)
{
string foldername;
string path;
string combinedpath;
{

foldername = "testfolder";
path = @"C:\blogexample";
combinedpath = path + @"\" + foldername;

if
(Directory.Exists(combinedpath))
label1.Text = "Directory exists";
else
label1.Text = "Directory doesn't exist";

}

How to create a folder with a MS-DOS command

To create a folder/directory using a DOS command, do the following :

Open up a command window i.e. Winkey + R and type cmd into the field and press Enter.
Type : md c:\Testfolder and press Enter

That's it, you will now have a folder called 'Testfolder' on your C drive !

Specify username and password within an FTP URL address

If you are using Windows explorer to access an FTP site you will know that you enter the username and hostname to be taken to the relevant site i.e. ftp:// username@hostname/. You would then be prompted for your password which you would enter into a dialogue box.

However, there is a short cut you can use to take you straight into the directory by just adding or clicking URL. The structure of this is as follows :

ftp:// username : password@hostname/

Although, this is a time saver it does have its dangers with regard to security. For example, the password will be visible in plain text and the username and password can be retrieved from your explorer/browser history if someone else accesses your pc.