Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
On May 18th at 10AM EDT we will answer your QlikView questions live. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
adam_stefl
Contributor
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);

        }

0 Replies