PDA

View Full Version : ASP/ASP.NET question accessing images stored in visual foxpro tables


SimpleHuman
January 23rd, 2004, 08:13 AM
Hello folks,

I am struck with this secnario... lets see if any of my eCharchans has any clue to solve this issue.

I am having tiff images stored in visual foxpro 6.0 tables in memo fileds. I have to extract them and show them to user via ASP.NET pages.

I can extract the code using ADO in vb6 with this code:

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

cn.ConnectionString = "Provider=VFPOLEDB.1;" _
& "Data Source=" & path & ";Password="""";Collating Sequence=MACHINE"
cn.Open
rs.Open "select * from " & dbFile & " where seq_num='" & seq_num & "'", cn, adOpenStatic, adLockReadOnly
If rs.EOF <> True Then
getImage = rs!image1
Else
rs.Close
rs.Open "select * from " & dbFile & " where seq_num='" & seq_num & "'", _
cn, adOpenStatic, adLockReadOnly
If rs.EOF <> True Then
getImage = rs!image1
Else
getImage = vbNullString
End If
End If
rs.Close
cn.Close

and able to save it using this code:

Private Sub Save(filename As String, data() As Byte)
Dim fso As FileSystemObject
Dim ts As TextStream

Set fso = New FileSystemObject
Set ts = fso.CreateTextFile(filename, True)
ts.Write data
ts.Close
End Sub

....

Now, no matter what I try in ASP.NET its not working... can someone atleast give me a way to do this simple asp code!

Any help is much appreciated...

YedaAnna
January 23rd, 2004, 09:04 AM
try these links simple pai

http://www.aspsimply.com/load/file_view.asp

Basically, displaying images from DB needs BinaryWrite and GetChunk to retieves OLE data: Response.ContentType = "image/jpeg"

Check this out

http://www.everythingcyber.com/support/default.aspx?mainsrc=/Support/Help/GraphicsMill/DisplayingImagesfromDatabaseinASP.htm



Also,

http://www.aspfree.com/c/a/ASP.NET-Code/

(search for 'retrieving' on this page)

If you can have them images in a folder then

http://authors.aspalliance.com/brettb/RandomImageSelector.asp


Image display using ADO datastream
http://authors.aspalliance.com/nothingmn/default.aspx?whichpoll=nothingmn_3&aid=3


These might also help (provider)
http://www.dotnetforums.net/showthread.php?s=&threadid=77735&highlight=image+table

http://www.dotnetforums.net/showthread.php?s=&threadid=74248&highlight=image+table

SimpleHuman
January 28th, 2004, 08:03 AM
thanks yeda pai for all the links:) eventually I figured it out using .NET only! here is what I have done! who kya kehte hai na gore log ke ishtyle me... killed the sucker! :D:D

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim fileName As String = Request.QueryString("fileName")
Dim seqNum As String = Request.QueryString("seqNum")

Dim tmpCon As New OdbcConnection("Driver=Microsoft Visual FoxPro Driver; " + "SourceType=DBf;SourceDB=c:\temp;BackgroundFetch=No;")
Dim tmpCmd As New OdbcCommand("select image1 from " & fileName & " where seq_num =" & "'" & seqNum & "'", tmpCon)

Dim dr As OdbcDataReader

Try
tmpCon.Open()
dr = tmpCmd.ExecuteReader()

While dr.Read()
Response.Expires = 0
Response.Buffer = True
Response.Clear()

Response.ContentType = "image/tiff"
Response.AddHeader("Content-Disposition", "inline; filename=image.tiff")

Response.BinaryWrite(System.Text.Encoding.Default.GetBytes(dr("image1")))
End While

Catch Err As Exception
EchoClass.LoadErrorPage("STANDARD", Err.Message, Err.Source & vbNewLine & Err.StackTrace)

Finally
dr.Close()
tmpCon.Close()
End Try
End Sub

YedaAnna
January 28th, 2004, 08:08 AM
microsoft has made our lives much easier with the loads of namespaces that they have come up with. very little coding needed. at the same time if you want to tweak in ur own code or want to customize things, things get difficult. more so if you were a classic ASP programmer before. im having a hard time with .net these days:(.

anyways simple pai keep in touch kyonki im having to deal with a lot of .net issues, so will need ur help:)

SimpleHuman
January 28th, 2004, 08:14 AM
Any time yeda pai... if its regarding ASP.NET! I will try my best to answer:)

Indian
January 28th, 2004, 08:39 AM
how do i do the same task ..say inserting and retrieving image/text files into SQL Server database ?

what should be the data type set for this image/file field ?

YedaAnna
January 28th, 2004, 09:07 AM
use the image type for images. text or ntext for text files. binary for other files:)