Execute a Query using a dialog expression
This example shows how you can search documents using a DialogExpression. If you don't need all the document's data it's recommended to use GetDocumentsTableResult(Dialog, DialogExpression) extension method to get a DocumentsQueryTableResult for more optimized result.
Use a dialog expression
C#
using System;
using System.Collections.Generic;
using System.Linq;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class Examples
{
public static DocumentsQueryResult RunQuery(Dialog dialog)
{
var q = new DialogExpression()
{
Operation = DialogExpressionOperation.And,
Condition = new List<DialogExpressionCondition>()
{
DialogExpressionCondition.Create("SENDER", "A", "ZZZZ" )
},
Count = 100,
SortOrder = new List<SortedField>
{
SortedField.Create("DWSTOREDATETIME", SortDirection.Desc)
}
};
var queryResult = dialog.GetDocumentsResult(q);
foreach (var d in queryResult.Items)
{
Console.WriteLine("Hit {0}: \"{1}\" on {2}", d.Id, (d["SENDER"].Item as string) ?? "-", d.CreatedAt);
}
return queryResult;
}
}
}
Use a dialog expression asynchronously
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class ExamplesAsync
{
public static async Task<DocumentsQueryResult> RunQueryAsync(Dialog dialog)
{
var q = new DialogExpression()
{
Operation = DialogExpressionOperation.And,
Condition = new List<DialogExpressionCondition>()
{
DialogExpressionCondition.Create("SENDER", "A", "ZZZZ" )
},
Count = 100,
SortOrder = new List<SortedField>
{
SortedField.Create("DWSTOREDATETIME", SortDirection.Desc)
}
};
DocumentsQueryResult queryResult = await dialog.GetDocumentsResultAsync(q).ConfigureAwait(false);
foreach (var d in queryResult.Items)
{
Console.WriteLine("Hit {0}: \"{1}\" on {2}", d.Id, (d["SENDER"].Item as string) ?? "-", d.CreatedAt);
}
return queryResult;
}
}
}
Use a dialog expression to get table result asynchronously
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class ExamplesAsync
{
public static async Task<DocumentsQueryTableResult> RunQueryForTableAsync(Dialog dialog)
{
var q = new DialogExpression()
{
Operation = DialogExpressionOperation.And,
Condition = new List<DialogExpressionCondition>()
{
DialogExpressionCondition.Create("SENDER", "A", "ZZZZ" )
},
Count = 100,
SortOrder = new List<SortedField>
{
SortedField.Create("DWSTOREDATETIME", SortDirection.Desc)
}
};
DocumentsQueryTableResult queryResult = await dialog.GetDocumentsTableResultAsync(q).ConfigureAwait(false);
var senderIdx =
queryResult
.Headers
.Select(
(v, i)
=> new { header = v, index = i })
.First(h => h.header.FieldName == "SENDER")
.index;
foreach (var r in queryResult.Rows)
{
Console.WriteLine(@"Hit {0}: ""{1}""", r.Id, (r.Items[senderIdx] as string) ?? "-");
}
return queryResult;
}
}
}