Step 4 - Connecting
This topic describes how to connect to Qlik Sense, either via the hub or directly to a Qlik Sense app.
Connecting to the Qlik Sense hub
You can connect to the Qlik Sense hub.
Example: Connect to the Qlik Sense hub
private static void TraverseHub(ILocation location)
{
using (var hub = location.Hub())
{
Console.WriteLine("QV Product: " + hub.QTProduct());
Console.WriteLine("Product Version: " + hub.ProductVersion());
Console.WriteLine("OS Name: " + hub.OSName());
Console.WriteLine("OS Version: " + hub.OSVersion());
}
}
Connecting to a Qlik Sense app
You can connect directly to a Qlik Sense app.
Example: Connect to a Qlik Sense app
private static void ListApps(ILocation location)
{
foreach (var appIdentifier in location.GetAppIdentifiers())
{
try
{
using (var app = location.App(appIdentifier))// Location specified in Accessing
{
var layout = app.GetAppLayout();
Console.WriteLine(layout.Title + " [" + app.Type + "]");
}
}
catch (MethodInvocationException e)
{
Console.WriteLine("Could not open app: " + appIdentifier.AppName + Environment.NewLine + e.InvocationError.Message);
}
catch (TimeoutException e)
{
Console.WriteLine("Timeout for: " + appIdentifier.AppName + Environment.NewLine + e.Message);
}
}
}
Connecting to a Qlik Sense open application (app) without data
You can open a corrupt Qlik Sense application without data and reload your application. You can remove the data, move the Qlik Sense application and load the data again.
Example: Connect to a Qlik Sense open application without data
// Open without data
OpenApp(true);
// Open with data
OpenApp();
private void OpenApp(bool noData = false)
{
IApp app;
String appname = "YourAppName";
try
{
ILocation location = Qlik.Engine.Location.FromUri(new Uri("ws://127.0.0.1:4848"));
location.AsDirectConnectionToPersonalEdition();
var appIdentifier = location.AppWithNameOrDefault(appName);
if (appIdentifier == null)
{
MessageBox.Show(@"The app (" + appName + @") does not exist.");
return;
}
ISession session = Session.WithApp(appIdentifier, SessionType.Default);
app = location.App(appIdentifier, session, noData: noData);
}
catch (MethodInvocationException invocationException)
{
MessageBox.Show(@"Error for details see invocationException.InvocationError.Code.");
return;
}
catch (Exception exception)
{
MessageBox.Show(@"No engine found, make sure the engine is started and try again." + "\n" + exception.Message);
return;
}
NxAppLayout appLayout = app.GetAppLayout();
if (appLayout.IsOpenedWithoutData)
{
MessageBox.Show(@" - Opened without data");
}
else
{
MessageBox.Show(@" - Opened with data");
}
}
Did this page help you?
If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!