Document UpdateFromStream¶
Document UpdateFromStream¶
1ot = impact.gui.output_toolbox
2db = impact.active_database
3
4
5def read_stream(file):
6
7 # stream = CreateObject("ADODB.Stream")
8
9 stream.open()
10 stream.type = 1 # ad_type_binary
11 stream.load_from_file(file)
12
13 read_stream = stream
14
15
16ot.clear()
17
18cust = db.customers.find_by_code("ACME CORP")
19
20if cust is not None:
21 docs = cust.documents
22
23 if docs is None:
24 ot.add("No customer document support in the database")
25 else:
26 ot.add("customer document support is enabled in this database")
27
28 doc = docs.item("Acme Corporation Specifications.docx")
29
30 if not doc.isNone():
31 ot.add("Document: '" + doc.name + "', impact.creator: " + str(doc.added_by.login_id) + ", Size: " + str(doc.size) + " bytes, version: " + str(doc.version.as_string))
32
33 latest_doc = doc.latest_version
34 ot.add("Latest document: '" + latest_doc.name + "', impact.creator: " + str(latest_doc.added_by.login_id) + ", Size: " + str(latest_doc.size) + " bytes, version: " + str(latest_doc.version.as_string))
35 db.errors.clear()
36
37 if latest_doc.checkout():
38 ot.add("Successfully checked out document")
39
40 active_doc = latest_doc.active_checkout
41
42 source = r"C:\\Documents\\Acme Corporation Specifications v2.docx"
43
44 doc_stream = read_stream(source)
45 if active_doc.update_from_stream(doc_stream, source, 0):
46 ot.add("Successfully updated document from '" + str(source) + "'")
47
48 if active_doc.checkin(ipDocumentVersion.dvMajor, "Some checkin comments"):
49 ot.add("Successfully checked in document")
50 else:
51 ot.add("Unable to checkin document")
52
53 else:
54 ot.add("Unable to update document from '" + str(source) + "'")
55
56 else:
57 ot.add("Unable to checkout document")
58
59 if db.errors.count > 0:
60 impact.gui.output_toolbox.add(db.errors.last.description)
61
62 else:
63 ot.add("Unable to locate document")
64else:
65 ot.add("Unable to locate a customer")