Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 357 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If a folder does not exist, create it

#11
Just write this line:

System.IO.Directory.CreateDirectory("my folder");

- If the folder does **not exist yet**, it will be **created**.
- If the folder **exists already**, the line will be **ignored**.

Reference: [Article about Directory.CreateDirectory at MSDN][1]

*Of course, you can also write `using System.IO;` at the top of the source file and then just write `Directory.CreateDirectory("my folder");` every time you want to create a folder.*

[1]:

[To see links please register here]

Reply

#12
This method will create the folder if it does not exist and do nothing if it exists:

Directory.CreateDirectory(path);
Reply

#13
Use the below code. I use this code for file copy and creating a new folder.

string fileToCopy = "filelocation\\file_name.txt";
String server = Environment.UserName;
string newLocation = "C:\\Users\\" + server + "\\Pictures\\Tenders\\file_name.txt";
string folderLocation = "C:\\Users\\" + server + "\\Pictures\\Tenders\\";
bool exists = System.IO.Directory.Exists(folderLocation);

if (!exists)
{
System.IO.Directory.CreateDirectory(folderLocation);
if (System.IO.File.Exists(fileToCopy))
{
MessageBox.Show("file copied");
System.IO.File.Copy(fileToCopy, newLocation, true);
}
else
{
MessageBox.Show("no such files");
}
}
Reply

#14
The following code is the best line(s) of code I use that will create the directory if not present.

System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/temp/"));

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

[1]:

[To see links please register here]



Reply

#15
## Create a new folder, given a parent folder's path:

string pathToNewFolder = System.IO.Path.Combine(parentFolderPath, "NewSubFolder");
DirectoryInfo directory = Directory.CreateDirectory(pathToNewFolder);
// Will create if does not already exist (otherwise will ignore)

- path to new folder given
- directory information variable so you can continue to manipulate it as you please.


Reply

#16
**Use this code if the folder is not presented under the image folder or other folders**

string subPath = HttpContext.Current.Server.MapPath(@"~/Images/RequisitionBarCode/");

bool exists = System.IO.Directory.Exists(subPath);
if(!exists)
System.IO.Directory.CreateDirectory(subPath);

string path = HttpContext.Current.Server.MapPath(@"~/Images/RequisitionBarCode/" + OrderId + ".png");
Reply

#17
##### Use **`System.IO.Directory.CreateDirectory`**.

<br>

According to the official [".NET" docs][1], you don't need to check if it exists first.

> ##### [System.io][2]   >   [Directory][3]   >   [Directory.CreateDirectory][1]
> Any and all directories specified in `path` are created, unless they already exist or unless some part of `path` is invalid. If the directory already exists, this method does not create a new directory, but it returns a `DirectoryInfo` object for the existing directory.
> ######         ***[— learn.microsoft.com/dotnet/api/][4]***
----------------------------------------


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through