Extract Files from Documents |
Scroll |
TheDocument represents a so-called compound file, a file that may contain one or more files (e.g. 2 word files, a PDF and 3 JPEG images), usually belonging to the same topic or task. These individual files in an TheDocument are often referred to as streams. The Step By Step guide illustrates how to extract one or all of these streams from a retrieved TheDocument.
1 |
Connect to the Thereforeā¢ server (see "Server - Connect and Disconnect" for Details) |
2 |
Declare and initialize a new TheDocument instance. |
3 |
Retrieve the document from the server. |
4 |
Extract all file streams to the specified directory using ExtractStream and the StreamCount property. |
Requirements and Assumptions: Document number 42 exists in your Thereforeā¢ system. Paths "C:\temp" and "C:\temp\extract" are valid on your system. If these assumptions do not apply to your system or configuration please replace them with appropriate values when copying the code samples below. Visual Basic Imports Therefore.API '...
' 1. Connect to the Thereforeā¢ server Dim server As New TheServer server.Connect(TheClientType.CustomApplication)
' 2. Declare and initialize a new Thereforeā¢ document Dim doc As New TheDocument
' 3. Retrieve the document from the server to the inbox Dim inbox As String = "C:\\temp\\" Dim docNo As Integer = 42 Dim filename As String = doc.Retrieve(docNo,inbox,server)
' 4. Extract all file streams to the specified directory Dim extractDir As String = "C:\\temp\\extract" Dim i As Integer For i = 0 To doc.StreamCount - 1 Step i + 1 Dim extractFile As String = doc.ExtractStream(i, extractDir) Console.WriteLine("File stream extracted to " + extractFile) Next C# using Therefore.API; //...
// 1. Connect to the Thereforeā¢ server TheServer server = new TheServer(); server.Connect(TheClientType.CustomApplication);
// 2. Declare and initialize a new Thereforeā¢ document TheDocument doc = new TheDocument();
// 3. Retrieve the document from the server to the inbox string inbox = "C:\\temp\\"; int docNo = 42; string filename = doc.Retrieve(docNo, inbox, server);
// 4. Extract all file streams to the specified directory string extractDir = "C:\\temp\\extract"; for (int i = 0; i < doc.StreamCount; i++) { string extractFile = doc.ExtractStream(i, extractDir); Console.WriteLine("File stream extracted to " + extractFile); } |
Using the Default Thereforeā¢ Inbox If the empty string ("") is passed as the second (strInbox) parameter of the Retrieve method, the default Thereforeā¢ inbox will be used for retrieval. |