Solved

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

Posted on 2004-08-25
15
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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