<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi all,<br>
<br>
A noob question, I have trouble trying to port an existing vb.net
snippet to pascal. <br>
Can anyone provide a code snippet where we can download and view a
file from a Database? A binary(jpeg/pdf file) was uploaded to a
database table. The code will just download the file uploaded and
view it. <br>
<br>
In vb.net this can be done:<br>
<br>
<i> if conn.State = ConnectionState.Closed Then
conn.Open()</i><i><br>
</i><i> sql = "Select binfile from graphicfiles WHERE
id=" & id</i><i><br>
</i><i><br>
</i><i> cmd = New NpgsqlCommand(sql, conn)</i><i><br>
</i><i><br>
</i><i> Dim fileData As Byte() =
DirectCast(cmd.ExecuteScalar(), Byte())</i><i><br>
</i><i><br>
</i><i> Dim sTempFileName As String = Path.GetTempPath
& "\" & sFileName</i><i><br>
</i><i><br>
</i><i> If Not fileData Is Nothing Then</i><i><br>
</i><i><br>
</i><i> 'Read image data into a file stream </i><i><br>
</i><i> Using fs As New FileStream(sTempFileName,
FileMode.OpenOrCreate, FileAccess.Write)</i><i><br>
</i><i> fs.Write(fileData, 0, fileData.Length)</i><i><br>
</i><i> 'Set image variable value using memory
stream. </i><i><br>
</i><i> fs.Flush()</i><i><br>
</i><i> fs.Close()</i><i><br>
</i><i> End Using</i><i><br>
</i><i><br>
</i><i> Process.Start(sTempFileName) 'Open file</i><i><br>
</i><i><br>
</i><i> End If</i><i><br>
</i><br>
Thanks,,<br>
Allan<br>
</body>
</html>