Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-08-25
15
Medium Priority
?
209 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 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