The following code example illustrates how to file an existing document in a folder. This example assumes a web reference named CEWS has been set to the following URI: http://localhost:<port>/wsi/FNCEWS40MTOM/wsdl.
using System; using Microsoft.Web.Services3; using Microsoft.Web.Services3.Security.Tokens; using Microsoft.Web.Services3.Design; using filedocument_ex.CEWS; namespace filedocument_ex { /// <summary> /// File a document in a folder. /// </summary> class Class1 { static void Main(string[] args) { const string strUrl = "http://localhost:9080/wsi/FNCEWS40MTOM/"; // Change port number if necessary const string strObjStoreName = "ContentEngineExs"; // Pre-existing object store string strContainmentName = "FiledDoc"; // Containment name to assign string strFolderPath = "/TestFolder"; // Pre-existing folder in the object store System.DateTime dateCreated = new System.DateTime(); // Create a wse-enabled web service object FNCEWS40ServiceWse wseService = new FNCEWS40ServiceWse(); // Set security token with your username and password UsernameToken token = new UsernameToken("username", "password", PasswordOption.SendPlainText); wseService.SetClientCredential(token); Policy MyPolicy = new Policy(); MyPolicy.Assertions.Add(new UsernameOverTransportAssertion()); wseService.SetPolicy(MyPolicy); wseService.Url = strUrl; wseService.RequireMtom = true; // Add default locale info to SOAP header Localization objDefaultLocale = new Localization(); objDefaultLocale.Locale = "en-US"; // Build the Create action for a DynamicReferentialContainmentRelationship object CreateAction objCreate = new CreateAction(); objCreate.classId = "DynamicReferentialContainmentRelationship"; // Assign the action to the ChangeRequestType element ChangeRequestType objChangeRequestType = new ChangeRequestType(); objChangeRequestType.Action = new ActionType[1]; objChangeRequestType.Action[0] = (ActionType)objCreate; // Assign Create action // Specify the target object (an object store) for the actions objChangeRequestType.TargetSpecification = new ObjectReference(); objChangeRequestType.TargetSpecification.classId = "ObjectStore"; objChangeRequestType.TargetSpecification.objectId = strObjStoreName; objChangeRequestType.id = "1"; // Build a list of properties to set in the doc ModifiablePropertyType[] objInputProps = new ModifiablePropertyType[3]; // Specify and set a string-valued property for the ContainmentName property SingletonString prpContainmentName = new SingletonString(); prpContainmentName.propertyId = "ContainmentName"; prpContainmentName.Value = strContainmentName; objInputProps[0] = prpContainmentName; // Add to property list // Specify the scope of the search ObjectStoreScope objObjectStoreScope = new ObjectStoreScope(); objObjectStoreScope.objectStore = strObjStoreName; // Create the search for unfiled doc RepositorySearch objRepositorySearch = new RepositorySearch(); objRepositorySearch.repositorySearchMode = RepositorySearchModeType.Rows; objRepositorySearch.repositorySearchModeSpecified = true; objRepositorySearch.SearchScope = objObjectStoreScope; // A document with this DocumentTitle property value must exist objRepositorySearch.SearchSQL = "SELECT [Id] FROM [Document] WHERE ([DocumentTitle] = 'DemoDoc')"; // Invoke the ExecuteSearch operation ObjectSetType objObjectSet = wseService.ExecuteSearch(objRepositorySearch); // Get ID of the first doc returned SingletonId prpId = (SingletonId)objObjectSet.Object[0].Property[0]; // Create an object reference to the document to file ObjectReference objDocument = new ObjectReference(); objDocument.classId = "Document"; objDocument.objectStore = strObjStoreName; objDocument.objectId = prpId.Value; // Create an object reference to the folder in which to file the document ObjectSpecification objFolder = new ObjectSpecification(); objFolder.classId = "Folder"; objFolder.objectStore = strObjStoreName; objFolder.path = strFolderPath; // Specify and set an object-valued property for the Head property SingletonObject prpHead = new SingletonObject(); prpHead.propertyId = "Head"; prpHead.Value = (ObjectEntryType)objDocument; // Set its value to the Document object objInputProps[1] = prpHead; // Add to property list // Specify and set an object-valued property for the Tail property SingletonObject prpTail = new SingletonObject(); prpTail.propertyId = "Tail"; prpTail.Value = (ObjectEntryType)objFolder; // Set its value to the folder object objInputProps[2] = prpTail; // Add to property list // Assign list of DRCR properties to set in ChangeRequestType element objChangeRequestType.ActionProperties = objInputProps; // Build a list of properties to exclude on the new DRCR object that will be returned string[] strExcludeProps = new string[2]; strExcludeProps[0] = "Owner"; strExcludeProps[1] = "DateLastModified"; // Assign the list of excluded properties to the ChangeRequestType element objChangeRequestType.RefreshFilter = new PropertyFilterType(); objChangeRequestType.RefreshFilter.ExcludeProperties = strExcludeProps; // Create array of ChangeRequestType elements and assign ChangeRequestType element to it ChangeRequestType[] objChangeRequestTypeArray = new ChangeRequestType[1]; objChangeRequestTypeArray[0] = objChangeRequestType; // Create ChangeResponseType element array ChangeResponseType[] objChangeResponseTypeArray = null; // Build ExecuteChangesRequest element and assign ChangeRequestType element array to it ExecuteChangesRequest objExecuteChangesRequest = new ExecuteChangesRequest(); objExecuteChangesRequest.ChangeRequest = objChangeRequestTypeArray; objExecuteChangesRequest.refresh = true; // return a refreshed object objExecuteChangesRequest.refreshSpecified = true; try { // Call ExecuteChanges operation to implement the DRCR creation objChangeResponseTypeArray = wseService.ExecuteChanges(objExecuteChangesRequest); } 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 (objChangeResponseTypeArray==null || objChangeResponseTypeArray.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 prpProperty in objChangeResponseTypeArray[0].Property) { // If property found, store its value if (prpProperty.propertyId == "ContainmentName") { strContainmentName = ((SingletonString)prpProperty).Value; break; } } // Capture value of the DateCreated property in the returned doc object foreach (PropertyType prpProperty in objChangeResponseTypeArray[0].Property) { // If property found, store its value if (prpProperty.propertyId == "DateCreated") { dateCreated = ((SingletonDateTime)prpProperty).Value; break; } } Console.WriteLine("The DRCR " + strContainmentName + " was successfully created " + dateCreated + "."); Console.WriteLine("Press Enter to end"); Console.ReadLine(); } } }