Solved

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

Posted on 2004-08-25
15
202 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
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 …

808 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