How to read properties from an ADP project by C#?

331 views Asked by At

Since I need to update my Adp file for my Clients I have added a new metadata property in my adp project which is by access 2003 and it shows the version of my adp file. I have used this article to establish this metadata and fortunately, it works fine.

https://www.pcreview.co.uk/threads/accessing-custom-properties-for-an-adp-file.2921635/

But actually, the problem is that how can I read this adp project metadata property from a C# project? And then I will start my updating process

I have tried the solution in this Article but it didn't work, because the container function had not name and owner property!

How to modify MS Access database Properties collection (not data!) from a C# program?

If anyone knows the practical solution please reply here.

And my second question is that if adp project has Visual basic lock for protection of viewing source code, what would be happened to C# project? is it still possible to read metadata properties or Not !?

I am using Windows 10-64 Bit, Access 2003 and Visual Studio 2013

1

There are 1 answers

0
MHN JAM On

After lots of seeking, I have found the solution and I wanna mention for those who maybe need that in the future.

Here is the code that you should add in your C# source code.

        using Access = Microsoft.Office.Interop.Access;

        private void button1_Click(object sender, EventArgs e)
    {

       Access.Application oAccess = new Access.Application();
       oAccess.OpenCurrentDatabase(@"C:\test\test.adp", false);
       var Version = oAccess.Run("GetMyVersion");//Name of procedure in Access module
       MessageBox.Show(Version.ToString());
       oAccess.CloseCurrentDatabase();


        foreach (Process Proc in Process.GetProcesses())
        if (Proc.ProcessName.Equals("MSACCESS"))  
        Proc.Kill();
    }

Note: You have to change your Platform configuration from Any CPU to X86.

It is obvious that you should have a "GetMyVersion" function in your Adp project to return the value of version. Even if you lock your Adp project this code works conveniently.

Good Luck!