Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
While googling, I saw a code which download a file from gridview. But It is not working.

What I want to do is :
When I click the download on the gridview. It will download the file into specific folder.


Try Dim filePath As String = "~\" + GridView1.Rows(GridView1.SelectedIndex).Cells(1).Text

            Dim fileName As String = Path.GetFileName(filePath)

            Dim stream As System.IO.Stream = Nothing

            stream = New FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
            Dim bytesToRead As Long = stream.Length
            Response.ContentType = "application/octet-stream"

            Response.AddHeader("content-Disposition", "attachment; filename=" & fileName)

            While bytesToRead > 0
                If Response.IsClientConnected Then
                    Dim buffer As Byte() = New [Byte](9999) {}
                    Dim length As Integer = stream.Read(buffer, 0, 10000)
                    Response.OutputStream.Write(buffer, 0, length)
                    Response.Flush()
                    bytesToRead = bytesToRead - length
                Else

                    bytesToRead = -1
                End If
            End While
   Catch ex As Exception
        End Try
Posted
Updated 7-Oct-14 19:12pm
v3

as long as you're using the latest MySQL Connector/Net version (*) (AND)
are not running on XP, It should be pretty much the same - except instead of creating a connection to MS SQL, you create a connection to the MYSQL database

None of the code you posted is relevant

(*) see here http://www.mysql.com/downloads/connector/net/[^]
 
Share this answer
 
Comments
NekoNao 8-Oct-14 1:04am    
I mean in the code. How will I change it? I know how to use mysql connector.
Garth J Lancaster 8-Oct-14 1:17am    
change the connection string - this shows you how to specify for MYSQL if you dont already know that http://www.connectionstrings.com/mysql/
Hi,

I agree with Garth. Download the connector and then create a connection in web.config as
XML
<connectionStrings>
    <add name="ConnectionString" connectionString="Server=localhost;userid=userid;password=pwd;Database=Databasename" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>


And then you can use this as
C#
MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);


Bind the grid and then use your code.

Regards,
Praneet
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900