0

How can I possibly make a directory or folder for the uploaded files in C# program? I want to upload files like PDF and store it in my documents>my_folder.

Also, I want to check if the folder exist then it wont create but if not, it will create a new folder inside the my documents folder.

tshepang
  • 12,111
  • 21
  • 91
  • 136
user3258603
  • 149
  • 2
  • 17

3 Answers3

0

Use the following to create a directory

System.IO.Directory.CreateDirectory("path");

And use:

System.IO.Directory.Exists("path")

to check if the folder exists already.

The first one will create the folder while the second one will return true or false, based on which you should do your logic.

Amit Joki
  • 58,320
  • 7
  • 77
  • 95
0

You do not have to do the creation check

Directory.CreateDirectory("path");

This Creates all directories and subdirectories in the specified path unless they already exist.

http://msdn.microsoft.com/en-us/library/54a0at6s(v=vs.110).aspx

If the directory already exists, this method does not create a new directory, but it returns a DirectoryInfo object for the existing directory.

Murdock
  • 4,352
  • 3
  • 34
  • 63
0

Please see: Save File to MyDocuments + App Folder which describes how to check for a subfolder in the My Documents folder. If it fails the check you can then use System.IO.Directory.CreateDirectory to create your folder.

Community
  • 1
  • 1
Kevin Adams
  • 123
  • 7