Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9043917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:51:12+00:00 2026-06-16T10:51:12+00:00

I want to read MSI file(Windows Installer Package). I have written a function as

  • 0

I want to read MSI file(Windows Installer Package). I have written a function as below which takes two input parameters : msifileName and Table Name and returns a data table which is one of the MSI table.

public DataTable ReadMsiPropertyTable(string msiFile, string tableName)
    {            
        Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");

        WindowsInstaller.Installer installer = (WindowsInstaller.Installer)Activator.CreateInstance(installerType);

        Database database = installer.OpenDatabase(msiFile, 0);

        string sqlQuery = String.Format("SELECT * FROM {0}",tableName);

        View view = database.OpenView(sqlQuery);

        view.Execute(null);

        Record record = view.Fetch();

        DataTable msiPropertyTable = new DataTable();

        msiPropertyTable.Columns.Add("Column1", typeof(string));
        msiPropertyTable.Columns.Add("Column2", typeof(string));
        msiPropertyTable.Columns.Add("Column3", typeof(string));
        msiPropertyTable.Columns.Add("Column4", typeof(string));

        while (record != null)
        {
            int fieldCount;
            fieldCount = record.FieldCount;

            msiPropertyTable.Rows.Add(record.get_StringData(0), record.get_StringData(1), record.get_StringData(2), record.get_StringData(3));                
            record = view.Fetch();
        }
        return msiPropertyTable;
    }

Using above code snippet, the number of rows and columns of Record are not known. SO I am statically returning only four columns. I want to return all the rows and columns of MSI Table which are in record.

So Please let me know how can I convert output of view or record to Dataset and then bind to Datatable. Or is there any other way to return all the rows and columns. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:51:13+00:00Added an answer on June 16, 2026 at 10:51 am

    Here’s similar logic using the interop types rather then the DTF types. As you can see it’s a lot more work. It’s also a lot more fragile since COM is involved instead of P/Invoke. Also, if you can eliminate the requirement to create an ADO.NET DataTable, DTF supports LINQ queries and databinding. In other words, I wrote this for fun only. I would NEVER use this method in real code.

     public static DataTable ReadMsiPropertyTable(string msiFile, string tableName)
            {
                DataTable dataTable = new DataTable(tableName);
                Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
                Installer installer = (WindowsInstaller.Installer)Activator.CreateInstance(installerType);
                Database database = installer.OpenDatabase(msiFile, MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);
    
                string sqlQuery = String.Format("SELECT * FROM {0}", tableName);
                View view = database.OpenView(sqlQuery);
                view.Execute(null);
    
                Record names = view.ColumnInfo[MsiColumnInfo.msiColumnInfoNames];
                Record types = view.ColumnInfo[MsiColumnInfo.msiColumnInfoTypes];
                Record row = view.Fetch();
    
                for (int index = 1; index < names.FieldCount+1; index++)
                {
                    string columnName = names.get_StringData(index);
                    string columnSpec = types.get_StringData(index);
    
                    switch (columnSpec.Substring(0, 1).ToLower())
                    {
                        case "s":
                            dataTable.Columns.Add(columnName, typeof(String));
                            break;
    
                        case "l":
                            dataTable.Columns.Add(columnName, typeof(String));
                            break;
    
                        case "i":
                            dataTable.Columns.Add(columnName, typeof(Int32));
                            break;
    
                        case "v":
                            dataTable.Columns.Add(columnName, typeof (Stream));
                            break;
                    }
                }
    
                while (row != null)
                {
                    DataRow dataRow = dataTable.NewRow();
                    for (int index = 0; index < dataTable.Columns.Count; index++)
                    {
    
                        if(dataTable.Columns[index].DataType == typeof(String))
                        {
                            dataRow[index] = row.StringData[index + 1];
                        }
                        else if(dataTable.Columns[index].DataType == typeof(Int32))
                        {
                            dataRow[index] = row.IntegerData[index + 1];
                        }
                        else if(dataTable.Columns[index].DataType == typeof(Stream))
                        {
                           // Insanity has it's limits. Not implemented.
                        }
                    }
                    dataTable.Rows.Add(dataRow);
                    row = view.Fetch();
                }
                return dataTable;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file. I want read that file. But In that if
i want to read an html file by using jquery get function, replace some
I want to read the pdf file from raw folder if devices have any
I want to read only first two lines in a batch file and store
I have two question : I have a data on binary file. I want
I have an xml file, inside views folder and I want read it, before
I try to read pdf file. I want to use this function databuffer =
I have a der file 'text.der' that contains a DER-encoded key. I want read
I want read the content of file and store it in array. I have
Hi I can't understand this error I want read this XML file: <?xml version=1.0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.