简体   繁体   中英

Downloading files to newly created directories in C#

I am creating directories on the fly and I would like to download files to the newly created directory:

// The code to create the directory based on revision number and original name
System.IO.Directory.CreateDirectory(@"C:\Users\bob\Desktop\Hello\Files\" + "v" + fileInfo.RevisionNumber + "_" + fileInfo.OriginalName);

// This method downloads files and takes 4 parameters. 
// The only one that really matters is the second one, targetFolder, 
// which is a String value. Any idea on how I can download the files 
// to the newly created directory (above) using the method below?
ecm.RetrieveFile(fileInfo.ID, targetFolder, recreateDirectoryStructureFlag, overwriteWithoutPromptFlag);
var targetFolder = @"C:\Users\bob\Desktop\Hello\Files\" + "v" + fileInfo.RevisionNumber + "_" + fileInfo.OriginalName;
System.IO.Directory.CreateDirectory(targetFolder);
ecm.RetrieveFile(fileInfo.ID, targetFolder, recreateDirectoryStructureFlag, overwriteWithoutPromptFlag);

Pass the same string that you passed to CreateDirectory .
It may be useful to put the string in a separate variable and pass the variable to both functions.

CreateDirectory returns a DirectoryInfo object. If you store that returned object, you can then pass newDirectory.FullPath to the download function.

string targetFolder= System.IO.Directory.CreateDirectory(@"C:\Users\bob\Desktop\Hello\Files\" + "v" + fileInfo.RevisionNumber + "_" + fileInfo.OriginalName).FullName;

ecm.RetrieveFile(fileInfo.ID, targetFolder, recreateDirectoryStructureFlag, overwriteWithoutPromptFlag);

I learned that the DirectoryInfo object has a FullName method that returns the full path. I used this method to get the path.

Thanks all for the help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM