473,394 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Download file from sql database.

Hi,

I have trouble in downloading the excel file from sql database.
After downloading, i try to open it, the error msg prompt:"The file in not
in a recognizable format"

Any ideas? i already out of ideas.

Here is my download excel file code:
Function GetFile()

Dim PROD_CONNEC As SqlConnection = New
SqlConnection("Server=gl;uid=LBPCOS;pwd=new1;datab ase=DB")
Dim PROD_CMD As SqlCommand = New SqlCommand("wla_getfile",
PROD_CONNEC)
Dim PROD_DR As SqlDataReader

PROD_CMD.CommandType = CommandType.StoredProcedure

Dim PRM_CP As New SqlParameter("@Attachment_ID", SqlDbType.Int)
PRM_CP.Value = CInt("2")
PROD_CMD.Parameters.Add(PRM_CP)

PROD_CONNEC.Open()
PROD_DR = PROD_CMD.ExecuteReader
If PROD_DR.Read Then
Response.ContentType = PROD_DR("Contenttype").ToString
Response.OutputStream.Write(CType(PROD_DR("Filedat a"), Byte()),
0, CInt(PROD_DR("Filesize")))
Response.AddHeader("Content-Disposition", "attachment;filename="
+ PROD_DR("Filename").ToString())
Else
Response.Write("File Not Found.")
End If

PROD_CONNEC.Close()

End Function
Below is my upload file code:
Function UploadFile()

Dim PROD_CONNEC As SqlConnection = New
SqlConnection("Server=gl;uid=LBPCOS;pwd=new1;datab ase=DB")
Dim PROD_CMD As SqlCommand = New SqlCommand("wla_fileupload",
PROD_CONNEC)
Dim iLength As Integer = CType(File1.PostedFile.InputStream.Length,
Integer)

If iLength = 0 Then Exit Function 'not a valid file
Dim sContentType As String = File1.PostedFile.ContentType
Dim sFileName As String, i As Integer
Dim bytContent As Byte()
ReDim bytContent(iLength) 'byte array, set to file size

'strip the path off the filename
i = InStrRev(File1.PostedFile.FileName.Trim, "\")
If i = 0 Then
sFileName = File1.PostedFile.FileName.Trim
Else
sFileName = Right(File1.PostedFile.FileName.Trim,
Len(File1.PostedFile.FileName.Trim) - i)
End If

PROD_CMD.CommandType = CommandType.StoredProcedure

Dim PRM_CP As New SqlParameter("@FileName", SqlDbType.NVarChar)
PRM_CP.Value = sFileName
PROD_CMD.Parameters.Add(PRM_CP)

Dim PRM_CP2 As New SqlParameter("@FileSize", SqlDbType.Real)
PRM_CP2.Value = iLength
PROD_CMD.Parameters.Add(PRM_CP2)

Dim PRM_CP3 As New SqlParameter("@FileData", SqlDbType.Image)
PRM_CP3.Value = bytContent
PROD_CMD.Parameters.Add(PRM_CP3)

Dim PRM_CP4 As New SqlParameter("@ContentType", SqlDbType.NVarChar)
PRM_CP4.Value = sContentType
PROD_CMD.Parameters.Add(PRM_CP4)

PROD_CONNEC.Open()
PROD_CMD.ExecuteNonQuery()
PROD_CONNEC.Close()
End Function

Your help will be appreciated.

Best Regards,
Daniel

Nov 19 '05 #1
0 1126

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: js | last post by:
Hi, how to do this: the page is to be able to allow a user to enter a password so as to download documents. It does not meant for any users to download. It is for some specific users. What I want...
0
by: Ilia Makarenko | last post by:
Hi everyone! I've got a problem with IIS 6.0 when downloading files with size > 4 Mb. So I am trying to download file in chunks, but it doesn't work. Only pert of the file is downloaded (~6.5 of...
4
by: mphanke | last post by:
Hi, how can I connect to a restricted directory on a server and download a file, if there is a newer version, than the one on the local file system? Something like ...
1
by: user2008 | last post by:
Hi all, I want to track how many times visitor download file from my website, for example, when visitor click on a download link, a ASPX page will be requested, after that it will redirect to a...
0
by: bonita | last post by:
If I add the code for user to download the file (e.g. if(File.Exists(FILE_NAME)){......}), the ASP.NET will give the following timeout error: Timeout expired. The timeout period elapsed prior to...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
8
by: BiT | last post by:
Hello, I'm working right now on project in vb.net 2005 for my company, i need the project to download file from the company web site. In order to get the file i have to give the site address...
3
by: cypherkro | last post by:
Hi I have a requirement to automatically download a file using a WebBrowser control without having the "Download File" pop up windows display. I cannot use Webclient!! I am using VS2005, .net2...
5
by: vinodkus | last post by:
dear sir/madam I have to write a code for download file using asp. please help me thanks in advance
1
by: vikassawant | last post by:
Hi, I m facing some critical problem for downloading 5mb file from server. Does anyone know? How to reduce the time to download file from server using HTTP connection?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.