in Search
 
Home Blogs Forums Marketplace Files
 
 
 

Creating database and adding files using API

Last post 08-29-2008, 12:46 AM by Bhavesh Rathod. 1 replies.
Sort Posts: Previous Next
  •  08-26-2008, 4:00 AM 14158

    Creating database and adding files using API

    I have created a application which checks if the database exists or not if not it will create the database and then add document to the newly created document.

    Problem

    1. Once the database is created, and attached to the server, i am unable to set the database object so that i can add the document.

    Source code can be downloaded from www.rincon.net/download/AlcTest.zip (192 KB)

    Using alchemy 8.2 with service pack 4.

    Need help.


    Rgds,
    Bhavesh Rathod
    Rincon India Solutions Pvt. Ltd.
    www.rincon.co.in
  •  08-29-2008, 12:46 AM 14173 in reply to 14158

    Re: Creating database and adding files using API

    Please find the code here. Need urgent help

     Sub InsertIntoAlchemy()
      Dim AlcApp As New Alchemy.Application
      Dim SelectedDB As Alchemy.Database
      Dim AlcParentItem As Alchemy.Item
      Dim alcBuilder As Alchemy.Builder
      Try
       Dim ReturnValue As Boolean = Check_AlchemyDatabase(AlcApp, SelectedDB, Now)
       If Not ReturnValue Then
        CreateDatabase(Now)
        Check_AlchemyDatabase(AlcApp, SelectedDB, Now)
       End If

    'Error here after creating database and attaching on the alchemy server.

       AlcParentItem = SelectedDB.Root.CreateItem(Alchemy.AuPosEnum.auPosLastChild, "d:\1.tif")

      Catch ex As Exception
       WriteLog("InsertIntoAlchemy", ex.Message.ToString)
      Finally
       alcBuilder = Nothing
       AlcParentItem = Nothing
       SelectedDB = Nothing
       AlcApp = Nothing
      End Try
     End Sub

     Function Check_AlchemyDatabase(ByVal AlcApp As Alchemy.Application, ByRef selectedDB As Alchemy.Database, ByVal FaxReceiveddate As Date) As Boolean
      Try
       CreateAlchemyINI()
       With AlcApp
        .LoadOptionsFile(System.AppDomain.CurrentDomain.BaseDirectory & "\Alchemy.ini")
        If .Databases.Count > 0 Then
         selectedDB = .Databases(1)
         For Each Db As Alchemy.Database In .Databases
          If Db.Path.Contains(Format(FaxReceiveddate, "yyMM").ToString & ".ald") Then
           selectedDB = Db
           Return True
          End If
         Next
        End If
       End With
       Return False
      Catch ex As Exception
       WriteLog("Check_AlchemyDatabase", ex.ToString)
       Return False
      End Try
     End Function

     Sub CreateDatabase(ByVal FaxReceiveddate As Date)
      Try
       Dim AlcAppLocal As New Alchemy.Application
       Dim NewDB As String = Format(FaxReceiveddate, "yyMM").ToString & ".ald"
       Dim NewDBTitle As String = Format(FaxReceiveddate, "MMMM yyyy").ToString
       Dim DatabasePath As String = "D:\Al_Dbs\" 'Registry.LocalMachine.OpenSubKey("System\CurrentControlSet\Services\Archival", False).GetValue("DatabasePath")
       AlcAppLocal.LoadOptionsFile(System.AppDomain.CurrentDomain.BaseDirectory & "\Alchemy.ini")
       Dim NewAuDB As Alchemy.Database = AlcAppLocal.CreateDatabase(DatabasePath & NewDB, NewDBTitle, , False, System.AppDomain.CurrentDomain.BaseDirectory & "\DB\DirectFax.ald", , , False)
       NewAuDB.Logout()
       NewAuDB = Nothing
       AlcAppLocal = Nothing
       Dim AUSRV As New AuServerApi.Application
       With AUSRV
        .Connect("127.0.0.1")
        .AddDatabase(DatabasePath & NewDB)
        .DisconnectAll()
       End With
       AUSRV = Nothing
      Catch ex As Exception
       WriteLog("CreateDatabase", ex.ToString)
      End Try
     End Sub

     Sub CreateAlchemyINI()
      Dim InFile As New System.IO.StreamWriter(System.AppDomain.CurrentDomain.BaseDirectory & "\Alchemy.ini")
      With InFile
       .WriteLine("[Open Databases]")
       Dim AUSRV As New AuServerApi.Application
       AUSRV.Connect("127.0.0.1")
       Dim dblist As Array = AUSRV.DatabaseList
       For Each DB As String In dblist
        .WriteLine(AUSRV.DatabaseUrl(DB) & "=" & AUSRV.DatabaseTitle(DB))
       Next
       .Close()
       AUSRV.DisconnectAll()
       AUSRV = Nothing
      End With
      InFile.Dispose()
      InFile = Nothing
     End Sub

     Sub WriteLog(ByVal func As String, ByVal msg As String)
      MsgBox(func & " : " & msg)
     End Sub


    Rgds,
    Bhavesh Rathod
    Rincon India Solutions Pvt. Ltd.
    www.rincon.co.in
View as RSS news feed in XML
  Privacy    Site Terms   Contact Administrator