Quick Start (Base64): Writing a resource using the web service API

The following C# code example writes a resource called loan.xdp in the repository. The resource is added to the /Applications/FormsApplication/1.0/FormsFolder location. (See Writing Resources.)

/* 
    * Ensure that you create a .NET client assembly that uses  
    * base64 encoding. This is required to populate a BLOB  
    * object with data or retrieve data from a BLOB object. 
    *  
    * For information, see "Invoking LiveCycle using Base64 Encoding"  
    * in Programming with LiveCycle 
    */ 
using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Data; 
using System.IO; 
 
namespace RepositoryWebService 
{ 
       class WriteFile 
       { 
           [STAThread] 
           static void Main(string[] args) 
           { 
               // This example will write a resource to the LiveCycle repository. 
               try 
               { 
                   //Create a RepositoryServiceService object 
                   RepositoryServiceService repositoryClient = new RepositoryServiceService(); 
                   repositoryClient.Credentials = new System.Net.NetworkCredential("administrator", "password"); 
 
                   // Specify the URI of the target folder for writing the resource 
                   String testFolderUri = "/Applications/FormsApplication/1.0/FormsFolder"; 
 
                   // Create the resource to be written to the folder 
                   Resource xdpResource = new Resource(); 
                   xdpResource.id = new Id(); 
                   xdpResource.lid = new Lid(); 
                   xdpResource.name = "Loan.xdp"; 
                   xdpResource.description = "An XDP file"; 
 
                   // Add content to the resource by: 
                   // 1. Creating a ResourceContent object. 
                   // 2. Creating a data document and passing it into the ResourceContent object. 
                   // 3. Specifying the size of the data document in the ResourceContent object. 
                   // 4. Passing the the ResourceContent object to the Resource object. 
                   ResourceContent newContent = new ResourceContent(); 
     
                   //Specify the location of the XDP file to add  
                   string xdpPath = "C:\\Adobe\Loan.xdp"; 
                   FileStream fs = new FileStream(xdpPath, FileMode.Open); 
 
                   //Get the length of the file stream  
                   int len = (int)fs.Length; 
                   byte[] xdpByteArray = new byte[len]; 
 
                   //Populate the byte array with the contents of the FileStream object 
                   fs.Read(xdpByteArray, 0, len); 
     
                   //Create a BLOB object to store the XDP file 
                   BLOB newFile = new BLOB(); 
                   newFile.binaryData = xdpByteArray; 
                   newContent.dataDocument = newFile; 
                   newContent.size = xdpByteArray.Length; 
 
                   //Place the ResourceContent instance into the Resource instance 
                   xdpResource.content = newContent; 
 
                   // Write the resource to the folder 
                   repositoryClient.writeResource(testFolderUri, xdpResource, null, null); 
 
                   // Retrieve the resource's URI 
                   String resourceUri = testFolderUri + "/" + xdpResource.path; 
 
                   // Print the resource verification message 
                   Console.WriteLine("the path to the new content is " + resourceUri); 
               } 
               catch (Exception e) 
               { 
                   Console.WriteLine( 
                       "Exception thrown while trying to write the resource" + 
                       e.Message 
                   ); 
               } 
 
           } 
       } 
} 
 

// Ethnio survey code removed