public void RunExample() { // start access Access.Application accessApplication = new Access.Application(); // create a utils instance, not need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(accessApplication); // create database file name string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example01", Access.Tools.DocumentFormat.Normal); // delete old database if exists if (System.IO.File.Exists(documentFile)) System.IO.File.Delete(documentFile); // create database DAO.Database newDatabase = accessApplication.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral); // close access and dispose reference accessApplication.Quit(AcQuitOption.acQuitSaveAll); accessApplication.Dispose(); // show dialog for the user(you!) HostApplication.ShowFinishDialog(null, documentFile); }
public void RunExample() { // start access Access.Application accessApplication = new Access.Application(); // create a utils instance, not need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(accessApplication); // create database file name string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example03", Access.Tools.DocumentFormat.Normal); // delete old database if exists if (System.IO.File.Exists(documentFile)) System.IO.File.Delete(documentFile); // create database DAO.Database newDatabase = accessApplication.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral); accessApplication.DBEngine.Workspaces[0].Close(); // setup database connection 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= < access2007 OleDbConnection oleConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=" + documentFile); oleConnection.Open(); // create table OleDbCommand oleCreateCommand = new OleDbCommand("CREATE TABLE NetOfficeTable(Column1 Text, Column2 Text)", oleConnection); oleCreateCommand.ExecuteReader().Close(); // write some data with plain sql & close for (int i = 0; i < 20000; i++) { string insertCommand = string.Format("INSERT INTO NetOfficeTable(Column1, Column2) VALUES(\"{0}\", \"{1}\")", i, DateTime.Now.ToShortTimeString()); OleDbCommand oleInsertCommand = new OleDbCommand(insertCommand, oleConnection); oleInsertCommand.ExecuteReader().Close(); } oleConnection.Close(); // delete old file if exists string newDocumentFile = string.Format("{0}\\CompactDatabase{1}", HostApplication, utils.File.FileExtension(Access.Tools.DocumentFormat.Normal)); if (File.Exists(newDocumentFile)) File.Delete(newDocumentFile); // now we do CompactDatabase accessApplication.DBEngine.CompactDatabase(documentFile, newDocumentFile); // close access and dispose reference accessApplication.Quit(AcQuitOption.acQuitSaveAll); accessApplication.Dispose(); // show dialog for the user(you!) HostApplication.ShowFinishDialog(null, documentFile); }
/// <summary> /// Creates an instance of the class /// </summary> /// <param name="owner">owner instance</param> protected internal FileUtils(CommonUtils owner) { if (null == owner) throw new ArgumentNullException("owner"); _owner = owner; }
private void buttonStartExample_Click(object sender, EventArgs e) { // start access _accessApplication = new Access.Application(); CommonUtils utils = new CommonUtils(_accessApplication); Office.CommandBarButton commandBarBtn = null; // add a commandbar popup Office.CommandBarPopup commandBarPopup = (Office.CommandBarPopup)_accessApplication.CommandBars["Menu Bar"].Controls.Add(MsoControlType.msoControlPopup, null, null, null, true); commandBarPopup.Caption = "commandBarPopup"; #region few words, how to access the picture /* you can see we use an own icon via .PasteFace() is not possible from outside process boundaries to use the PictureProperty directly the reason for is IPictureDisp: http://support.microsoft.com/kb/286460/de its not important is early or late binding or managed or unmanaged, the behaviour is always the same For example, a COMAddin running as InProcServer and can access the Picture Property */ #endregion #region CommandBarButton // add a button to the popup commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, null, null, null, true); commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption; commandBarBtn.Caption = "commandBarButton"; Clipboard.SetDataObject(HostApplication.DisplayIcon.ToBitmap()); commandBarBtn.PasteFace(); commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click); #endregion // make visible _accessApplication.Visible = true; buttonStartExample.Enabled = false; buttonQuitExample.Enabled = true; }