Here is some useful documentation.

You're going to want to make a class that extends %CSP.REST and set up an application that uses that class as its dispatch class. You'll have a URL map in that class to tell IRIS or Cache what to do with the request. Depending on your specific application, you might also want to get familiar with using %request and %response in that process.

When you're projecting a list of a class to XML, you usually have a parent element for each of those objects, then a separate element for each of it's properties. So I think what you'd need to do would be something more like:

<Results>
    <PersonIDs>
        <PersonID>
            <PersonID>1000000</PersonID>
        </PersonID>
        <PersonID>  
            <PersonID>1000001</PersonID>
        </PersonID>  
        <PersonID>  
            <PersonID>1000005</PersonID>
        </PersonID>  
    </PersonIDs> 
</Results>

So that the outer PersonID element indicates your PersonID object, and the PersonID inside of that is the PersonID property of that object.

Here's a possible alternative to using SqlComputeCode.

You can override the getter method for that property so that it always returns the related document name. In your Question class, define your docFileName property as:

Property docFileName As %String [ReadOnly];

You'll want it to be read only because you aren't going to want to be able to set this property in the question object. You're going to want to retrieve it from the document object. If it could also be set here, you'd have things weirdly out of sync. Then, in that same class, include the following method:

Method docFileNameGet() As %String{
    if ..Document '= ""{
        return ..Document.FileName
    }
    else{
        return ""
    }
}

Once you do that, whenever you refer to the question's docFileName, it'll give you the document's file name, or an empty string if there isn't one.

Rochdi, when you say you've figured out how to save it to C:\Temp\filename.csv, are you saying you have it saved on the client, or on the server?

If it's saving the file on the server, you can create a class that extends %CSP.StreamServer, then override the OnPreHTTP and OnPage class methods like this for simple text files:

 Class fileserver Extends %CSP.StreamServer
{ 
ClassMethod OnPreHTTP() As %Boolean
{
do %response.SetHeader("Content-Type","text/csv")
do %response.SetHeader("Content-Disposition","attachment;filename=""myfile.csv""")
quit 1
} 
ClassMethod OnPage() As %Status
{
set file = ##class(%File).%New("/path/to/file.csv")
do file.Open("R")
while file.AtEnd '= 1{
write file.ReadLine(),!
}
quit $$$OK
} 
}

and then just link to it that page to download.

Once you get to things that aren't plain text, it gets a little more complicated, but this should work for a simple csv.