2011-07-20 58 views
1

我正在使用(以前稱爲Hummingbird Enterprise)OpenText eDocs文檔管理系統。以編程方式將文檔添加到Hummingbird/OpenText eDocs數據庫

http://www.opentext.com/2/global/products/products-opentext-edocs-products/products-opentext-edocs-document-management.htm

我們仍在使用蜂鳥5.1.0.5。

我一直在評論這個軟件的API文檔,但有些地方有些模糊。 到目前爲止,我可以創建我的配置文件表單,填充一些值。

DOCSObjects.Application docApp = null; 
DOCSObjects.IProfile profile = null; 
Type fType = Type.GetTypeFromProgID("DOCSObjects.Application"); 
docApp = (DOCSObjects.Application)Activator.CreateInstance(fType); 
try { profile = docApp.CurrentLibrary.CreateProfile("DEF_PROF"); } 
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } 
if (profile != null) 
{ 
    try 
    { 
     profile.Columns["DOCNAME"].Value = "New PDF Document"; 
     profile.Columns["APP_ID"].Value = "ACROBAT"; 
     profile.ShowProfile(1); 
     // not sure how to set a document here 
     profile.SetDocument(docApp.CurrentLibrary.Name, document); 
     profile.Save(); // requires a short flag, but what? 
    } 
    catch (Exception ex) 
    { 
     System.Diagnostics.Debug.WriteLine(ex.Message); 
    } 
} 
else 
{ 
    MessageBox.Show("Profile is null"); 
} 

我遇到麻煩的是如何使用配置文件保存文檔。 我正在使用C#,並且API文檔和智能感知只需要在對象上請求文檔。 這是否意味着路徑或我是否需要將PDF加載到某個特定的DOCSObjects類型?

另外,API文檔在保存文檔時引用了常量,例如OF_NORMAL。我認爲這是0,但還有其他我應該知道的?文檔中引用的許多常量沒有定義值。 (所有的例子都在C++/VB中)。

我知道任何人都在使用這個軟件,但認爲我會試一試。 謝謝,感謝您的幫助。

回答

2

我已經在VB中完成了它 - 使用我創建的API包裝器。您應該使用DM API文件夾下的PCDClient而不是DOCSObjects。

這裏的代碼很可能不會馬上爲你工作,因爲它是高度定製的,但是可以玩弄它,你也可以弄明白。祝你好運!

Public Sub CreateProfile(ByRef Doc As Profile) 

    Try 
     'SET THE STATIC META DATA 
     Doc.objDoc.SetProperty("TYPE_ID", "DOCS") ' DOCUMENT TYPE IS ALWAYS DOCS 
     Doc.objDoc.SetProperty("TYPIST_ID", RDIMSAPI._UserID) 
     Doc.objDoc.SetProperty("APP_ID", RDIMSData.GetApp(Doc.FileToImport)) ' FILE TO IMPORT 

     'CREATE THE DOCUMENT 
     Doc.objDoc.Create() 
     If Doc.objDoc.ErrNumber <> 0 Then 
      Throw New Exception(Doc.objDoc.ErrNumber & " - " & Doc.objDoc.ErrDescription) 
     End If 

     'RETRIEVE THE NEW DOCUMENT PROFILE 
     Dim DocNumber As Integer = Doc.objDoc.GetReturnProperty("%OBJECT_IDENTIFIER") 
     Dim VersionID As Integer = Doc.objDoc.GetReturnProperty("%VERSION_ID") 

     'ADD THE DOCUMENT TO THE PROFILE 
     Dim objPutDoc As New PCDClient.PCDPutDoc 
     objPutDoc.SetDST(RDIMSAPI._sDST) 
     objPutDoc.AddSearchCriteria("%TARGET_LIBRARY", RDIMSAPI._Library) 
     objPutDoc.AddSearchCriteria("%DOCUMENT_NUMBER", DocNumber) 
     objPutDoc.AddSearchCriteria("%VERSION_ID", VersionID) 
     objPutDoc.Execute() 
     If objPutDoc.ErrNumber <> 0 Then 
      Throw New Exception(Doc.objDoc.ErrNumber & " - " & Doc.objDoc.ErrDescription) 
     End If 
     objPutDoc.NextRow() 

     'UPLOAD THE DOCUMENT 
     Dim objPutStream As PCDClient.PCDPutStream = objPutDoc.GetPropertyValue("%CONTENT") 
     Dim fs As FileStream = System.IO.File.OpenRead(Doc.FileToImport) 
     Dim fi As FileInfo = New System.IO.FileInfo(Doc.FileToImport) 
     Dim br As BinaryReader = New BinaryReader(fs) 
     Dim addDocBytes As Byte() = br.ReadBytes(CInt(fs.Length)) 
     br.Read(addDocBytes, 0, addDocBytes.Length) 
     br.Close() 
     Dim bytesWritten As Integer = 0 
     objPutStream.Write(addDocBytes, addDocBytes.Length, bytesWritten) 
     objPutStream.SetComplete() 

     'UNLOCK THE DOCUMENT 
     Dim objDoc As New PCDClient.PCDDocObject 
     objDoc.SetDST(RDIMSAPI._sDST) 
     objDoc.SetObjectType("0_RDIMSPROF_SYS") 
     objDoc.SetProperty("%TARGET_LIBRARY", RDIMSAPI._Library) 
     objDoc.SetProperty("%OBJECT_IDENTIFIER", DocNumber) 
     objDoc.SetProperty("%VERSION_ID", VersionID) 
     objDoc.SetProperty("%STATUS", "%UNLOCK") 
     objDoc.Update() 
     objDoc.Fetch() 
     objDoc = Nothing 
     If Doc.objDoc.ErrNumber <> 0 Then 
      Throw New Exception(Doc.objDoc.ErrNumber & " - " & Doc.objDoc.ErrDescription) 
     End If 

     'RELEASE ALL OBJECTS AND RETURN DOCUMENT NUMBER 
     objPutDoc = Nothing 

    Catch ex As Exception 
     'IF EXCEPTION, LOG ERROR AND DISPLAY MESSAGE 
     Throw New Exception("(" & Me.GetType().FullName & "." & New StackTrace(0).GetFrame(0).GetMethod.Name & ") " & ex.Message) 
     Exit Sub 
    End Try 

End Sub 
1

我不知道你是否還在嘗試。但這是我的C#代碼。它是更大模塊的一部分,因此它不會立即生效。 配置文件參數將是例如「DEF_PROF」。

這也使用PCDClientLib。我的理解是,這些是服務器端庫,只能在服務器上使用。而且你應該使用你已經用於客戶端代碼的庫。

// All variable prepended with an underscore are class fields etc... 
// DMImportException is a custom exception, nothing special really 

/// <summary> 
/// Import a file into the library previously logged in to. 
/// </summary> 
/// <param name="profile">The name of the used profile.</param> 
/// <param name="profileNameValues">A dictionary of strings containing the profile values wich should be saved for the document.</param> 
/// <param name="FileName">The path and filename of the file to import.</param> 
public virtual void ImportFile(string profile, Dictionary<string, string> profileNameValues, string FileName) 
{ 
    if (!_isLoggedIn) 
    { 
     throw new DMImportException("Trying to import a file while not logged in into DM."); 
    } 

    int totalbyteswritten; 
    byte[] bdata; 

    bdata = file.readallbytes(filename); 

    pcddocobject objdoc = new pcddocobject(); 
    objdoc.setproperty("%target_library", _library); 
    objdoc.setdst(_dst); 
    objdoc.setobjecttype(profile); 

    foreach(var profilenamevaluepair in profilenamevalues) 
    { 
     objdoc.setproperty(profilenamevaluepair.key, profilenamevaluepair.value); 
    } 

    objdoc.create(); 

    if (objdoc.errnumber != 0) 
    { 
     throw new dmimportexception("error while creating a new objdoc. check the inner error.", objdoc.errnumber, objdoc.errdescription); 
    } 

    _docnumber = objDoc.GetReturnProperty("%OBJECT_IDENTIFIER").ToString(); 
    _versionID = objDoc.GetReturnProperty("%VERSION_ID").ToString(); 

    PCDPutDoc objPutDoc = new PCDPutDoc(); 

    objPutDoc.SetDST(_dst); 
    objPutDoc.AddSearchCriteria("%TARGET_LIBRARY", _library); 
    objPutDoc.AddSearchCriteria("%DOCUMENT_NUMBER", _docNumber); 
    objPutDoc.AddSearchCriteria("%VERSION_ID", _versionID); 
    objPutDoc.Execute(); 

    if (objPutDoc.ErrNumber != 0) 
    { 
     throw new DMImportException("RecentEdit Failure on Execute: Error while trying to get a handle to the newly created doc. Check the inner error.", objPutDoc.ErrNumber, objPutDoc.ErrDescription); 
    } 

    objPutDoc.NextRow(); 

    PCDPutStream objPutStream = (PCDPutStream)objPutDoc.GetPropertyValue("%CONTENT"); 

    objPutStream.Write((object)bdata, (int)bdata.Length, out TotalBytesWritten); 

    objPutStream.SetComplete(); 

    objPutStream = null; 
    objDoc = null; 

    objDoc = new PCDDocObject(); 
    objDoc.SetDST(_dst); 
    objDoc.SetObjectType(profile); 
    objDoc.SetProperty("%TARGET_LIBRARY", _library); 
    objDoc.SetProperty("%OBJECT_IDENTIFIER", _docNumber); 
    objDoc.SetProperty("%VERSION_ID", _versionID); 
    objDoc.SetProperty("%STATUS", "%UNLOCK"); 
    objDoc.Update(); 

    if (objDoc.ErrNumber != 0) 
    { 
     throw new DMImportException("Error while trying to unlock the just imported file. Check the inner error.", objDoc.ErrNumber, objDoc.ErrDescription); 
    } 

    objPutDoc = null; 
    objDoc = null; 
    return; 
} 

附:我建議您更新到eDocs中的更高版本(我們從5.1.0.5升級到本週;-D 5.2.1結束)

---編輯---

我想您需要

Application.CurrentLibrary.CreateProfile("PROF_DEF").CreateVersionFromFile(/* filePath is one of the params */); 

如果您確實需要使用DM Ext進行此操作。 API代替DM API

相關問題