The following code example illustrates how to file an existing document in a folder. This example assumes a web reference named CEWS_SOAP has been set to the following URI: http://localhost:<port>/wsi/FNCEWS35SOAP/wsdl.
using System; using Microsoft.Web.Services2; using Microsoft.Web.Services2.Security.Tokens; using filedocument_ex.CEWS_SOAP; namespace filedocument_ex { /// <summary> /// File a document in a folder. /// </summary> class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { const string url = "http://localhost:9080/wsi/FNCEWS35SOAP/"; // Change port number if necessary const string objectStore = "ContentEngineExs"; // Pre-existing object store string containmentName = "FiledDoc"; // Containment name to assign string folderPath = "/TestFolder"; // Pre-existing folder in the object store System.DateTime dateCreated = new System.DateTime(); // Create a wse-enabled web service object to provide access to SOAP header FNCEWS35ServiceWse wseService = new FNCEWS35ServiceWse(); wseService.Url = url; SoapContext soapContext = wseService.RequestSoapContext; // Add security token to SOAP header with your username and password UsernameToken token = new UsernameToken("username", "password", PasswordOption.SendPlainText); soapContext.Security.Tokens.Add(token); // Add default locale info to SOAP header Localization defaultLocale = new Localization(); defaultLocale.Locale = "en-US"; // Build the Create action for a DynamicReferentialContainmentRelationship object CreateAction verbCreate = new CreateAction(); verbCreate.classId = "DynamicReferentialContainmentRelationship"; // Assign the action to the ChangeRequestType element ChangeRequestType elemChangeRequestType = new ChangeRequestType(); elemChangeRequestType.Action = new ActionType[1]; elemChangeRequestType.Action[0] = (ActionType)verbCreate; // Assign Create action // Specify the target object (an object store) for the actions elemChangeRequestType.TargetSpecification = new ObjectReference(); elemChangeRequestType.TargetSpecification.classId = "ObjectStore"; elemChangeRequestType.TargetSpecification.objectId = objectStore; elemChangeRequestType.id = "1"; // Build a list of properties to set in the new doc ModifiablePropertyType[] elemInputProps = new ModifiablePropertyType[3]; // Specify and set a string-valued property for the ContainmentName property SingletonString propContainmentName = new SingletonString(); propContainmentName.propertyId = "ContainmentName"; propContainmentName.Value = containmentName; elemInputProps[0] = propContainmentName; // Add to property list // Specify the scope of the search ObjectStoreScope elemObjectStoreScope = new ObjectStoreScope(); elemObjectStoreScope.objectStore = objectStore; // Create the search for unfiled doc RepositorySearch elemRepositorySearch = new RepositorySearch(); elemRepositorySearch.repositorySearchMode = RepositorySearchModeType.Rows; elemRepositorySearch.repositorySearchModeSpecified = true; elemRepositorySearch.SearchScope = elemObjectStoreScope; // A document with this DocumentTitle property value must exist elemRepositorySearch.SearchSQL = "SELECT [Id] FROM [Document] WHERE ([DocumentTitle] = 'DemoDoc')"; // Invoke the ExecuteSearch operation ObjectSetType objObjectSet = wseService.ExecuteSearch(elemRepositorySearch); // Get ID of the first doc returned SingletonId propId = (SingletonId)objObjectSet.Object[0].Property[0]; // Create an object reference to the document to file ObjectReference objDocument = new ObjectReference(); objDocument.classId = "Document"; objDocument.objectStore = objectStore; objDocument.objectId = propId.Value; // Create an object reference to the folder in which to file the document ObjectSpecification objFolder = new ObjectSpecification(); objFolder.classId = "Folder"; objFolder.objectStore = objectStore; objFolder.path = folderPath; // Specify and set an object-valued property for the Head property SingletonObject propHead = new SingletonObject(); propHead.propertyId = "Head"; propHead.Value = (ObjectEntryType)objDocument; // Set its value to the Document object elemInputProps[1] = propHead; // Add to property list // Specify and set an object-valued property for the Tail property SingletonObject propTail = new SingletonObject(); propTail.propertyId = "Tail"; propTail.Value = (ObjectEntryType)objFolder; // Set its value to the folder object elemInputProps[2] = propTail; // Add to property list // Assign list of DRCR properties to set in ChangeRequestType element elemChangeRequestType.ActionProperties = elemInputProps; // Build a list of properties to exclude on the new DRCR object that will be returned string[] excludeProps = new string[2]; excludeProps[0] = "Owner"; excludeProps[1] = "DateLastModified"; // Assign the list of excluded properties to the ChangeRequestType element elemChangeRequestType.RefreshFilter = new PropertyFilterType(); elemChangeRequestType.RefreshFilter.ExcludeProperties = excludeProps; // Create array of ChangeRequestType elements and assign ChangeRequestType element to it ChangeRequestType[] elemChangeRequestTypeArray = new ChangeRequestType[1]; elemChangeRequestTypeArray[0] = elemChangeRequestType; // Create ChangeResponseType element array ChangeResponseType[] elemChangeResponseTypeArray = null; // Build ExecuteChangesRequest element and assign ChangeRequestType element array to it ExecuteChangesRequest elemExecuteChangesRequest = new ExecuteChangesRequest(); elemExecuteChangesRequest.ChangeRequest = elemChangeRequestTypeArray; elemExecuteChangesRequest.refresh = true; // return a refreshed object elemExecuteChangesRequest.refreshSpecified = true; try { // Call ExecuteChanges operation to implement the DRCR creation elemChangeResponseTypeArray = wseService.ExecuteChanges(elemExecuteChangesRequest); } catch(System.Net.WebException ex) { Console.WriteLine("An exception occurred while creating a folder: [" + ex.Message + "]"); return; } // The new DRCR object should be returned, unless there is an error if (elemChangeResponseTypeArray==null || elemChangeResponseTypeArray.Length < 1) { Console.WriteLine("A valid object was not returned from the ExecuteChanges operation"); return; } // Capture value of the ContainmentName property in the returned doc object foreach (PropertyType propProperty in elemChangeResponseTypeArray[0].Property) { // If property found, store its value if (propProperty.propertyId == "ContainmentName") { containmentName = ((SingletonString)propProperty).Value; break; } } // Capture value of the DateCreated property in the returned doc object foreach (PropertyType propProperty in elemChangeResponseTypeArray[0].Property) { // If property found, store its value if (propProperty.propertyId == "DateCreated") { dateCreated = ((SingletonDateTime)propProperty).Value; break; } } Console.WriteLine("The DRCR " + containmentName + " was successfully created " + dateCreated + "."); } // Main } // Class1 }