Consultor Eletrônico



Kbase P105036: How to send a MS Word document to a .NET Open Client
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/28/2010
Status: Verified

GOAL:

How to send a MS Word document to a .NET Open Client

GOAL:

How to pass a file to a .NET Open Client via an AppServer

GOAL:

How to pass a MEMPTR variable to a .NET Open Client

FACT(s) (Environment):

Windows
OpenEdge 10.x

FIX:

In order to pass a Word document (or any file) to a .Net Open Client, the file has to be passed as a MEMPTR to the AppServer.

For example, the Progress 4GL procedure below returns a Word document as a MEMPTR:

/* GetDoc.p */
/* Output: Word Document is passed as a MEMPTR */

DEFINE OUTPUT PARAMETER pDoc as MEMPTR NO-UNDO.
FILE-INFO:FILE-NAME = "c:\temp\Test.doc".
SET-SIZE(pDoc) = FILE-INFO:FILE-SIZE.

/* Copying the Doc document into a MEMPTR variable */
INPUT FROM "c:\temp\Test.doc" BINARY NO-CONVERT.
IMPORT pDoc.
INPUT CLOSE.

After generating the .NET proxy with the procedure 'GetDoc' defined as a non-persistent procedure, the C# code looks like the following:

using <YourProxyNameSpace>; // NamesSpace of the .NET Proxy defined in the ProxyGen
using Progress.Open4GL;
using Progress.Open4GL.Proxy;

// NOTE: Replace the connection string below with your connection string

Connection conn = new Connection("AppServer://localhost:5162/asbroker1","","", "");
// Instantiante the AppObject
<YourAppObject> ao = new <YourAppObject>(conn);

Memptr pDoc ;

// Call P4GL procedure which returns a MEMPTR
ao.getDoc(out pDoc);
// Create a new .Doc document and copy the content of the Memptr variable
System.IO.FileStream oFileStream = new System.IO.FileStream("c:\\test.doc", System.IO.FileMode.Create);
oFileStream.Write(pDoc.Bytes, 0, pDoc.Bytes.Length - 1);
oFileStream.Close();
ao.Dispose();
conn.Dispose();