QMS API 文档中有一个示例,位于GetSourceDocumentFolders 方法下。该示例通过使用递归浏览子文件夹将所有文档和文件夹的名称写入控制台。
这并不完全是您所需要的,但您可以调整它以将它们存储在数组中,等等。我已尝试更改变量名称以匹配您已经提供的代码:
List<DocumentFolder> sourceDocumentsFolders = Client.GetSourceDocumentFolders(qvService[0].ID, DocumentFolderScope.General | DocumentFolderScope.Services);
foreach (DocumentFolder sourceDocumentFolder in sourceDocumentsFolders.OrderBy(x => x.General.Path)) {
// print the names of all source document folders, prefix with [R] for root folders
Console.WriteLine("[R] " + sourceDocumentFolder.General.Path);
// print all sub nodes of the current source document folder
PrintSourceDocumentNodes(Client, sourceDocumentFolder, string.Empty, 1);
}
static void PrintSourceDocumentNodes(IQMS apiClient, DocumentFolder sourceDocumentFolder, string relativePath, int indentationDepth) {
// retrieve all source document nodes of the given folder and under the specified relative path
List<DocumentNode> sourceDocumentNodes = apiClient.GetSourceDocumentNodes(sourceDocumentFolder.Services.QDSID, sourceDocumentFolder.ID, relativePath);
foreach (DocumentNode sourceDocumentNode in sourceDocumentNodes.OrderByDescending(x => x.IsSubFolder).ThenBy(x => x.Name)) {
// print the names of all source document nodes, indent and prefix with [F] for folders and [D] for documents
string indentation = new string(' ', indentationDepth * 3);
string nodePrefix = (sourceDocumentNode.IsSubFolder ? "[F]" : "[D]");
Console.WriteLine(indentation + nodePrefix + " " + sourceDocumentNode.Name);
// print all sub nodes of the current source document node if it represents a folder
if (sourceDocumentNode.IsSubFolder) {
PrintSourceDocumentNodes(apiClient, sourceDocumentFolder, relativePath + "\\" + sourceDocumentNode.Name, indentationDepth + 1);
}
}
}