Create a case with a document and an appendix

The example below displays how to create a case and then add a document with metadata to the newly created case in one transaction.

Example:


var context = ServiceFactory.GetODataService(); // Get the DataServiceContext of our OData service.
 
// The main document contents.
Document mainBlob = new Document();
context.AddToDocuments(mainBlob);
context.SetSaveStream(mainBlob, new System.IO.MemoryStream(Encoding.UTF8.GetBytes("Main document contents...")), true, "text/plain", "main.txt");
 
// The appendix document contents.
Document appendixBlob = new Document();
context.AddToDocuments(appendixBlob);
context.SetSaveStream(appendixBlob, new System.IO.MemoryStream(Encoding.UTF8.GetBytes("Appendix document contents...")), true, "text/plain", "appendix.txt");
 
// Upload the main and appendix document contents.
DataServiceResponse response = context.SaveChanges();
 
// Create the File (case)
File file = new File();
file.Title = "Title of my new case";
file.FileClass_Value = "99"; // Required - value can be diferent.
 
// A collection for tracking Records (the metadata of the Document and appendix)
DataServiceCollection<Record> records = new DataServiceCollection<Record>(context);
 
// Metadata for the main document
Record mainRecord = new Record();
mainRecord.Title = "The title of my main document";
mainRecord.File = file; // Associate this mainRecord with the File we just created.
mainRecord.RecordType_Value = "I"; // Required - value can be different.
mainRecord.State_Value = "UÅ"; // Required - value can be different. UÅ means Draft.
mainRecord.Document = mainBlob; // Associates the main document contents with the mainRecord.
 
Record appendix = new Record();
appendix.Title = "The title of my appendix document";
appendix.RecordType_Value = "I"; // Required - value can be different.
appendix.State_Value = "UÅ"; // Required - value can be different. UÅ means Draft.
appendix.MainRecord = mainRecord; // This will make the appendix an appendix of mainRecord.
appendix.Document = appendixBlob; // Associates the appendix document contents with this appendix record.
appendix.File = file; // Not really neccessary the File will default to the File of the mainRecord.
 
// Now ask the context to track the appendix. The file and the mainRecord will be tracked implicit thru the references from the appendix.
records.Add(appendix);
 
context.SaveChanges(SaveChangesOptions.Batch); // Upload all metadata to the server in one transaction.
				

Kopibilledet mangler

 

 

 

 

 

 

 

 

 

 

 

 

 

 

var context = ServiceFactory.GetODataService(); // Get the DataServiceContext of our OData service.

 

// The main document contents.

Document mainBlob = new Document();

context.AddToDocuments(mainBlob);

context.SetSaveStream(mainBlob, new System.IO.MemoryStream(Encoding.UTF8.GetBytes("Main document contents...")), true, "text/plain", "main.txt");

 

// The appendix document contents.

Document appendixBlob = new Document();

context.AddToDocuments(appendixBlob);

context.SetSaveStream(appendixBlob, new System.IO.MemoryStream(Encoding.UTF8.GetBytes("Appendix document contents...")), true, "text/plain", "appendix.txt");

 

// Upload the main and appendix document contents.

DataServiceResponse response = context.SaveChanges();

 

// Create the File (case)

File file = new File();

file.Title = "Title of my new case";

file.FileClass_Value = "99"; // Required - value can be diferent.

 

// A collection for tracking Records (the metadata of the Document and appendix)

DataServiceCollection<Record> records = new DataServiceCollection<Record>(context);

 

// Metadata for the main document

Record mainRecord = new Record();

mainRecord.Title = "The title of my main document";

mainRecord.File = file; // Associate this mainRecord with the File we just created.

mainRecord.RecordType_Value = "I"; // Required - value can be different.

mainRecord.State_Value = "UÅ"; // Required - value can be different. UÅ means Draft.

mainRecord.Document = mainBlob; // Associates the main document contents with the mainRecord.

 

Record appendix = new Record();

appendix.Title = "The title of my appendix document";

appendix.RecordType_Value = "I"; // Required - value can be different.

appendix.State_Value = "UÅ"; // Required - value can be different. UÅ means Draft.

appendix.MainRecord = mainRecord; // This will make the appendix an appendix of mainRecord.

appendix.Document = appendixBlob; // Associates the appendix document contents with this appendix record.

appendix.File = file; // Not really neccessary the File will default to the File of the mainRecord.

 

// Now ask the context to track the appendix. The file and the mainRecord will be tracked implicit thru the references from the appendix.

records.Add(appendix);

 

context.SaveChanges(SaveChangesOptions.Batch); // Upload all metadata to the server in one transaction.