The following code example demonstrates how to unfile a document from 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 unfiledocument_ex.CEWS; namespace unfiledocument_ex { /// <summary> /// Unfile a document from 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 const string strDocPath = "/TestFolder/DemoDoc"; // Path to a pre-existing document in object st // 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"; // Set a reference to the document ObjectSpecification objDocumentSpec = new ObjectSpecification(); objDocumentSpec.classId = "Document"; objDocumentSpec.path = strDocPath; objDocumentSpec.objectStore = strObjStoreName; // Create a property filter to get Containers property PropertyFilterType objPropFilter = new PropertyFilterType(); objPropFilter.maxRecursion = 1; objPropFilter.maxRecursionSpecified = true; objPropFilter.IncludeProperties = new FilterElementType[1]; objPropFilter.IncludeProperties[0] = new FilterElementType(); objPropFilter.IncludeProperties[0].Value = "Containers"; // Create the request for GetObjects ObjectRequestType[] request = new ObjectRequestType[1]; request[0] = new ObjectRequestType(); request[0].SourceSpecification =objDocumentSpec; request[0].PropertyFilter = objPropFilter; ObjectResponseType[] response; try { response = wseService.GetObjects(request); } catch(System.Net.WebException ex) { Console.WriteLine("An exception occurred while requesting a document: [" + ex.Message + "]"); return; } ObjectValue objResponse = null; if (response[0] is SingleObjectResponse) { objResponse = ((SingleObjectResponse)response[0]).Object; } // Get ReferentialContainmentRelationship object EnumOfObject objRes=(EnumOfObject)objResponse.Property.GetValue(0); ObjectValue objRCR=(ObjectValue)objRes.Value[0]; // unfile from first folder (assume document is only filed in one folder) // Create delete action DeleteAction docUnfile = new DeleteAction (); // Assign the action to the ChangeRequestType element ChangeRequestType[] objChangeRequestTypeArray = new ChangeRequestType[1]; ChangeRequestType objChangeRequestType = new ChangeRequestType(); objChangeRequestTypeArray[0] = objChangeRequestType; // Create ChangeResponseType element array ChangeResponseType[] objChangeResponseTypeArray; // 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; objChangeRequestType.Action = new ActionType[1]; objChangeRequestType.Action[0] = (ActionType)docUnfile; // Specify the target object (Reservation object) for the actions objChangeRequestType.TargetSpecification = new ObjectReference(); objChangeRequestType.TargetSpecification.classId = "ReferentialContainmentRelationship"; objChangeRequestType.TargetSpecification.objectId =objRCR.objectId; objChangeRequestType.TargetSpecification.objectStore = strObjStoreName; objChangeRequestType.id = "1"; // Assign ChangeRequestType element objChangeRequestTypeArray[0] = objChangeRequestType; // Build ExecuteChangesRequest element and assign ChangeRequestType element array to it objExecuteChangesRequest.ChangeRequest = objChangeRequestTypeArray; objExecuteChangesRequest.refresh = true; // return a refreshed object objExecuteChangesRequest.refreshSpecified = true; try { // Call ExecuteChanges operation to implement the Delete object objChangeResponseTypeArray = wseService.ExecuteChanges(objExecuteChangesRequest); } catch(System.Net.WebException ex) { Console.WriteLine("An exception occurred while checking out a document: [" + ex.Message + "]"); return; } // The new document object will 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; } Console.WriteLine("UnFile Document '{0}'.", strDocPath); Console.WriteLine("Press Enter to end"); Console.ReadLine(); } } }