[英]Downloading files to newly created directories in C#
我正在動態創建目錄,我想將文件下載到新創建的目錄中:
// 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
字符串相同。
將字符串放在單獨的變量中並將該變量傳遞給兩個函數可能會很有用。
CreateDirectory
返回DirectoryInfo
對象。 如果存儲該返回的對象,則可以將newDirectory.FullPath
傳遞給下載函數。
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方法,該方法返回完整路徑。 我使用這種方法來獲取路徑。
謝謝大家的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.