开发者

Downloading files to newly created directories in C#

开发者 https://www.devze.com 2023-03-30 22:37 出处:网络
I am creating directories on the fly and I would like to download files to the n开发者_Python百科ewly created directory:

I am creating directories on the fly and I would like to download files to the n开发者_Python百科ewly 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);


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消