Archive Documents |
Scroll |
Archiving is the process of adding new documents to the Thereforeā¢ system. The Step-by-Step guide below explains how to create a new document, add streams, edit index data values and store the document on the server.
1 |
Create a channel factory for the web service endpoint. |
2 |
Create a channel to the web service endpoint. |
3 |
Create requested parameter instances. |
4 |
Set a category number for the document's index data. |
5 |
Add one or more file streams to the document. |
6 |
Set some values in the document's index data. |
7 |
Execute a create operation to store documents on the server. |
8 |
Close the channel and channel factory. |
9 |
Process a response. |
// 1. Create a channel factory to the web service endpoint
...
ChannelFactory<IThereforeService> channelFactory = new ChannelFactory<IThereforeService>(binding, endpoint);
// 2. Create a channel to the web service endpoint
IThereforeService service = channelFactory.CreateChannel();
// 3. Create requested parameters
CreateDocumentParams parameters = new CreateDocumentParams();
string strFile = "d:\\data\\Order.doc";
string strFileName = Path.GetFileName(strFile);
string strExt = Path.GetExtension(strFile).Remove(0, 1);//remove dot
string strFromFolder = Path.GetDirectoryName(strFile);
// 4. Set the category you want to add the document to
parameters.CategoryNo = CategoryIds.FilesCategory;
// 5. Add a file stream to the document
parameters.Streams = new List<WSStreamInfoWithData>();
parameters.Streams.Add(new WSStreamInfoWithData { FileData = File.ReadAllBytes(strFile), FileName = strFileName, StreamNo = null });
// 6. Add the index data to the document
parameters.IndexDataItems = new List<WSIndexDataItem>();
parameters.IndexDataItems.Add(new WSIndexDataItem(new WSIndexDataString(CategoryIds.Files_Filename, strFileName)));
parameters.IndexDataItems.Add(new WSIndexDataItem(new WSIndexDataString(CategoryIds.Files_From_Folder, strFromFolder)));
parameters.IndexDataItems.Add(new WSIndexDataItem(new WSIndexDataString(CategoryIds.Files_Extension, strExt)));
parameters.IndexDataItems.Add(new WSIndexDataItem(new WSIndexDataDate(CategoryIds.Files_Creation_Date, DateTime.SpecifyKind(File.GetCreationTime(strFile), DateTimeKind.Unspecified))));
// 7. Execute a create operation to store a document on the server
CreateDocumentResponse response = service.CreateDocument(parameters);
// 8. Close the channel and channel factory.
((IClientChannel)service).Close();
channelFactory.Close();
// 9. Process response.
txt_result.Text += "Created document. No: " + response.DocNo + ". File added: " + strFileName + Environment.NewLine;