将文件下载到c#中新创建的目录

本文关键字:创建 文件下载 新创建 | 更新日期: 2023-09-27 18:06:34

我正在创建目录,我想下载文件到新创建的目录:

// 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);

将文件下载到c#中新创建的目录

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返回DirectoryInfo对象。如果您存储返回的对象,那么您可以将newDirectory.FullPath传递给下载函数。

传递与传递给CreateDirectory相同的字符串。
将字符串放在单独的变量中并将变量传递给两个函数可能会很有用。

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);

我了解到DirectoryInfo对象有一个返回完整路径的FullName方法。我使用这个方法来获取路径。

谢谢大家的帮助