Solved

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

Posted on 2004-08-25
15
193 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 18

Expert Comment

by:DotNetLover_Baan
Comment Utility
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
Comment Utility
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
Comment Utility
I am using Visual Basic.net forms. Do you have code for a form? Thanks.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

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

Author Comment

by:patrickkenney
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I tried the code.. but no error !!!... Which line is giving you error.. ?
0
 

Author Comment

by:patrickkenney
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now