我能够使用QMS api的以下代码成功获取qlikview文件列表。
string key = Client.GetTimeLimitedServiceKey();
ServiceKeyClientMessageInspector.ServiceKey = key;
ServiceInfo[] qvService = Client.GetServices(ServiceTypes.QlikViewServer);
DocumentNode[] allDocs = Client.GetUserDocuments(qvService[0].ID);
但现在这只列出了qlikview文件。文件夹怎么样?有人可以建议我获取文件夹的代码吗?
答案 0 :(得分:0)
GetSourceDocumentFolders
方法下的QMS API文档中有一个示例。该示例使用递归在子文件夹中导航,将所有文档和文件夹的名称写入控制台。
这不是您所需要的,但您可以对此进行调整以将它们存储在数组等中。我试图更改变量名称以匹配您已提供的代码:
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);
}
}
}