我在我的应用程序中使用了一个 FileUploader
控件。我想将文件保存到指定的文件夹。如果这个文件夹不存在,我想先创建一个,然后把我的文件保存到这个文件夹中。如果该文件夹已经存在,则只需将文件保存在其中即可。
我该怎么做?
最佳答案
使用System.IO.Directory.CreateDirectory
。
据官方".NET" docs ,你不需要先检查它是否存在。
System.io > Directory > Directory.CreateDirectory
Any and all directories specified in
path
are created, unless they already exist or unless some part ofpath
is invalid. If the directory already exists, this method does not create a new directory, but it returns aDirectoryInfo
object for the existing directory.— learn.microsoft.com/dotnet/api/
关于c# - 如果文件夹不存在,则创建它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9065598/