Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Highlighted
adam_stefl
New Contributor

Qlikview API Export Layout and Bookmarks Example

I ran into a situation the other day where I needed to export the layouts and bookmarks for all of my QVW files. Since I have 100+ I thought it would be best to create an application in VS 2015 C# to do it for me. After searching did find some discussions on it, but I thought I would like to share my solution.

The bulk of what I'm doing is below, I've attached my source for reference. Feel free to take a look.

        private void bgwExportQVWs_DoWork(object sender, DoWorkEventArgs e)

        {

            //start the Qlikview client.

            QlikView.Application QVapp = new QlikView.Application();

            //get the qvw files in the folder

            DirectoryInfo di = new DirectoryInfo(txtFilePath.Text);

            FileInfo[] fi = di.GetFiles(@"*.qvw");

            int iCount = 1; //this is for the progress bar.

            foreach (FileInfo f in fi)

            {

                //I did an override the backgroundworker to add a status property that I could pass the filename to.

                bgwExportQVWs.sStatus = f.FullName;

                bgwExportQVWs.ReportProgress(iCount);

                //create a directory to put the exports into.

                DirectoryInfo dd = System.IO.Directory.CreateDirectory(f.Directory + "\\" + f.Name.Replace(f.Extension, ""));

                try

                {

                    //open the document

                    QlikView.Document doc = (QlikView.Document)QVapp.OpenDoc(f.FullName);

                    //the app was running too fast and the document would sometimes not open correctly.

                    System.Threading.Thread.Sleep(1000);

                   //This is where the layout and bookmarks are extracted.

                    doc.ExportLayoutFile(dd.FullName + "\\Layout.xml");

                    doc.ExportBookmarks(dd.FullName + "\\BM.xml");

                    doc.ExportUserBookmarks(dd.FullName + "\\UBM.xml");

                    System.Threading.Thread.Sleep(1000);

                }catch(Exception ex)

                {

                    //document didn't open correctly? or some other error we don't care about. Go onto the next document.

                }

               

                try

                {

                    QVapp.ActiveDocument().CloseDoc();

                }catch(Exception ex)

                {

                    //document already closed or not opened go onto the next one.

                }

                iCount++;

            }

            QVapp.Quit(0);

        }