Solved

Retrieve uploaded file from sql 2000 based on record selected in datagrid.

Posted on 2004-08-25
15
203 Views
Last Modified: 2010-04-23
Here is my setup:

I have a form that displays filtered records from a sql 2000 database table in a datagrid. Example, a user can enter a record id click on SHOW RESULTS and see all the records of files that have been loaded to the database for that ID.

What I need to be able to do now is program the forms so a user can click on any one of the result records in the datagrid and dowload the file for that record to their desktop, word, or adobe(whatever the file is). I'm clueless as to where I should start with this. Thanks in advance for any and all help!!!!
0
Comment
Question by:patrickkenney
  • 7
  • 5
15 Comments
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11897231
Go for Crystal Reports. Create the file(pdf) in server, and let the user download it. Crystal reports can be saved as pdf files.
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 11898381
What kind of files do the records refer to?  Are these actual files on the file system of the server or are you thinking about exporting data to a file (like PDF, as Baan mentions)?

John
0
 

Author Comment

by:patrickkenney
ID: 11898687
The files the database will contain are .doc and .pdf files that were created outside this database. Emailed document will be uploaded and given and id and other field description. I need to be able to select a row from a datagrid and download the file in the database, not create a pdf in Crystal Report.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11898982
I guess you know how to create a "Select Button" column for your datagrid. Once done , write the appropriate code for "ItemCommand" event handler of the grid.

    Private Sub MyDataGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles MyDataGrid.ItemCommand
        Dim FileToDwnld As String = e.Item.Cells(1).Text  'Assuming that second column of the grid has the File name
        Response.Redirect(FileToDwnld)
    End Sub

this is an example.. write your code the way you stored the file... Here I assumed that you stored the File name in the database.

-Baan
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11898991
To start a new window...

    Private Sub MyDataGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles MyDataGrid.ItemCommand
        Dim FileToDwnld As String = e.Item.Cells(1).Text  'Assuming that second column of the grid has the File name
        Dim strScript As String = "<script language=JavaScript> </script>"
        strScript &= "window.open('" & FileToDwnld & "') ;"
        Page.RegisterStartupScript("MyScript", strScript)
End Sub
0
 

Author Comment

by:patrickkenney
ID: 11899000
I am using Visual Basic.net forms. Do you have code for a form? Thanks.
0
 

Author Comment

by:patrickkenney
ID: 11899024
disregard previous comment...didn't read all the way up
0
 

Author Comment

by:patrickkenney
ID: 11899029
spoke too soon, that looks like asp.net code. I need form code. Thanks
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 500 total points
ID: 11899108
oops.... The word "Download" is responsible for this... :))
Well, I would suggest get the row index and write your code in "CurrentCellChanged" event of the datagrid...

Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
         Dim FileToDwnld As String = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 0)
         'Say first column has the file address.

        Dim SavDlg As New SaveFileDialog
        SavDlg.FileName = FileToDwnld
        If SavDlg.ShowDialog() = DialogResult.OK Then
            Dim s1, s2 As FileStream
            Dim br As BinaryReader
            Dim bw As BinaryWriter

            '---read from the first file and write to a new file (will create a new file)
            s1 = New FileStream(FileToDwnld, FileMode.Open, FileAccess.Read)
            s2 = New FileStream(SavDlg.FileName, FileMode.Create, FileAccess.Write)

            br = New BinaryReader(s1)
            bw = New BinaryWriter(s2)

            Dim byteRead As Byte
            Dim j As Integer
            For j = 0 To br.BaseStream.Length() - 1
                byteRead = br.ReadByte
                bw.Write(byteRead)
            Next
            br.Close()
            bw.Close()
            s1.Close()
            s2.Close()
        End If
End Sub

-Baan
0
 

Author Comment

by:patrickkenney
ID: 11899213
No problem, that looks better :), but I get an error that says "Cast from 'Byte()' to type 'String' is not valid. Any ideas? Thanks!
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11899304
I tried the code.. but no error !!!... Which line is giving you error.. ?
0
 

Author Comment

by:patrickkenney
ID: 11899349
First line. Says it can't convert byte to string. The Column selected is a varbinary field if that helps. Any ideas?
0
 

Author Comment

by:patrickkenney
ID: 11904647
I think i figured out why that code doesn't work. I am not using pointers in the sql database. I have inserted files into the data column as binary large objects. I need to be able to pull a byte array out of column. Thanks!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question