Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Import Into MailSite with No GUI (VBA, VB)
PaulMost
Hi,
I have read number of code snippets on the forum and tried all related to following task: I have to import Excel document into default Worksite Database, with default profile, using path to actual file. It better be done in VBA, but VB is acceptable as long as this will work silently, without Interwoven screen popup.
However I failed to find the exact syntax in order to get working. I used following function in VBA, importing new file over the prior version, and Interwoven screen still shows up!
Can anyone advise?
Thanks a lot in advance!
Public Sub test_savenewver()
On Error GoTo Oops
Dim dms As New ManDMS
Dim sess As IManSession
Dim oSourcedoc As IManDocument
Dim oNewVer As IManDocument
Dim arrDox(0) As NRTDocument
Dim ps As IManProfileSearchParameters
Dim oCmd As ImportNewVersionCmd
Dim oContext As ContextItems
Dim bRefresh
Set sess = dms.Sessions.Add("AD")
sess.TrustedLogin
Set ps = dms.CreateProfileSearchParameters
ps.Add imProfileAuthor, sess.UserID
ps.Add imProfileCheckedOut, "N"
' One way to get a document object
Set oSourcedoc = sess.PreferredDatabase.GetDocument(649603, 1).LatestVersion ' Arbitrary example of a document number
Set arrDox(0) = oSourcedoc
Set oCmd = New ImportNewVersionCmd
Set oContext = New ContextItems
' Required
oContext.Add "SelectedNRTDocuments", arrDox
oContext.Add "DestinationObject", sess
'Optional
'oContext.Add "IManExt.Import.DeleteLocalFiles", True
oContext.Add "IManExt.Import.FileName", "H:\temp\newtest.doc"
oContext.Add "iManExt.NewVersionCmd.NoCmdUI", True
oContext.Add "Doctype", "EXCEL"
' Skips the NewVersion Profile dialog
oCmd.Initialize oContext
oCmd.Update
If oCmd.Status = (oCmd.Status And nrActiveCommand) Then
oCmd.Execute
bRefresh = oContext.Item("IManExt.Refresh")
Set oNewVer = oContext.Item("IManExt.NewversionCmd.Document")
End If
GoTo Cleanup
Oops:
MsgBox Err.Description
Err.Clear
Resume Next
Cleanup:
Set ps = Nothing
Set oSourcedoc = Nothing
Set sess = Nothing
Set dms = Nothing
End
End Sub
Find more posts tagged with
Comments
jny
Do you mean that you would like to import a new (Excel) document into WorkSite silently and that you would like to prepopulate the profile? If so, are you attempting to profile with the minimum required fields or end-user's default profile (which is set on the client-side)?
If it's the latter, it's rather difficult to do as it would first involve reading the default new profile from the following registry key: [HKEY_CURRENT_USER\Software\Interwoven\WorkSite\8.0\iManExt\DefaultNewProfile].
This would not be an easy task as it requires you to decode each value name representing the profile field. The SDK does not support an object that holds this input as it's not stored on the server-side.
After you have gathered the default new profile values, you may then use the imanage.dll API's to create the document, set the profile, and checkin the document file to WorkSite.
Here's a code example of how it's done:
[VB6]
==========================
Dim dms As New ManDMS
Dim sess As IManSession
Dim db As IManDatabase
Dim doc As IManDocument
Dim docclasses As IManDocumentClasses
Dim docclass As IManDocumentClass
Dim docsubclasses As IManDocumentClasses
Dim docsubclass As IManDocumentClass
Dim doctypes As IManDocumentTypes
Dim doctype As IManDocumentType
Dim importeddoc As IManDocument
Dim checkinResult As IManCheckinResult
Dim importPath As String
importPath = "C:\Temp\importtest.xls" 'Arbitrary example of a valid filepath.
On Error GoTo OOPS
Set sess = dms.Sessions.Add("DSS_WIN2003SERV")
sess.Login "jyee", "mhdocs"
'sess.TrustedLogin
Set db = sess.Databases.ItemByName("WSDSS1") 'Arbitrary example of a valid database.
' Verify document class
Set docclasses = db.SearchDocumentClasses("DOC", imSearchBoth, True)
If Not docclasses Is Nothing Then
' Get the item
Set docclass = docclasses.ItemByName("DOC")
' Check for required subclass
If True = docclass.SubClassRequired Then
' Example to get all the subclasses
Set docsubclasses = docclass.GetSubClasses("", imSearchBoth, True)
' Example to assume it's the first item in the collection
Set docsubclass = docsubclasses.ItemByIndex(1)
End If
End If
' Get document type by filepath
Set doctype = db.GetDocumentTypeFromPath(importPath)
If doctype Is Nothing Then
'Exit: failed to detect file type
MsgBox "Failed to detect file type."
Exit Sub
End If
' Create document object
Set doc = db.CreateDocument
' Profile
With doc
.SetAttributeByID imProfileAuthor, sess.UserID 'Example sets the current user as the author.
.SetAttributeByID imProfileOperator, sess.UserID 'Example sets the current user as the operator.
.SetAttributeByID imProfileClass, docclass.Name 'Arbitrary example of a valid class.
If Not docsubclass Is Nothing Then
.SetAttributeByID imProfileSubClass, docsubclass.Name
End If
.SetAttributeByID imProfileType, doctype.Name 'Arbitrary example of a valid application type.
'Checkin new document
Set checkinResult = .CheckInWithResults(importPath, imCheckinNewDocument, imDontKeepCheckedOut)
If True = checkinResult.Succeeded Then
MsgBox "Imported document successfully. New document database/number/ver: " & .Database.Name & ":" & .Number & "_" & .Version
Else
MsgBox checkinResult.ErrorCode & ": " & checkinResult.ErrorMessage
End If
End With
sess.Logout
dms.Close
'TODO: Free all pointers
==========================