473,386 Members | 1,705 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,386 software developers and data experts.

how to save file from database to user's local disc using asp.net(VB)

Hello, anyone
I had search for few days with how to save file when user choose a file name from listbox and i will search the file from database and user can save it into their desktop

what I had done currently is uploading a file to database but totally no idea about how to "download" from database

the following is my codes to upload file to database:
Expand|Select|Wrap|Line Numbers
  1.  If Not (myFile.PostedFile Is Nothing) Then
  2.  
  3.             OpenConn()
  4.             Dim intFileNameLength As Integer, bytData() As Byte
  5.             Dim objStream As System.IO.Stream
  6.             Dim strFileNamePath As String
  7.             Dim strFileNameOnly As String
  8.  
  9.             intFileNameLength = myFile.PostedFile.ContentLength
  10.             ReDim bytData(intFileNameLength)
  11.             objStream = myFile.PostedFile.InputStream
  12.             objStream.Read(bytData, 0, intFileNameLength)
  13.  
  14.             strFileNamePath = myFile.PostedFile.FileName
  15.             intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\")
  16.             strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2)
  17.  
  18.             Dim cmd As OracleCommand
  19.             cmd = New OracleCommand("INSERT INTO test (filename, filesave) Values ('" + strFileNameOnly + "',:1)", myCN)
  20.             cmd.CommandType = CommandType.Text
  21.  
  22.             Dim param As OracleParameter = cmd.Parameters.Add("filesave", OracleDbType.Blob) ' Bind the parameter as OracleDbType.Blob to command for inserting image
  23.             param.Direction = ParameterDirection.Input
  24.  
  25.             param.Value = bytData                                                           ' Assign Byte Array to Oracle Parameter
  26.             cmd.ExecuteNonQuery()
  27.  
  28.             CloseConn()
  29.             Label1.Text = "File Upload Success."
  30.         End If
  31.  
Please help me/ giv me some direction to go, I hav no idea at all
Thanks in advance
Sep 29 '08 #1
2 2499
For txt File

Step 1:
Expand|Select|Wrap|Line Numbers
  1. Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + "." + "txt")
fileName -> Give the File Name which you download

Step2:
Set the Content type
Expand|Select|Wrap|Line Numbers
  1.   Response.ContentType = "application/x-download"
Step 3:
Expand|Select|Wrap|Line Numbers
  1.   Response.Charset = ""
  2.   Response.WriteFile(<here Path>)
  3.   Response.End()
  4.  Response.Flush()
Sep 29 '08 #2
Frinavale
9,735 Expert Mod 8TB
For txt File

Step 1:
Expand|Select|Wrap|Line Numbers
  1. Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + "." + "txt")
fileName -> Give the File Name which you download

Step2:
Set the Content type
Expand|Select|Wrap|Line Numbers
  1.   Response.ContentType = "application/x-download"
Step 3:
Expand|Select|Wrap|Line Numbers
  1.   Response.Charset = ""
  2.   Response.WriteFile(<here Path>)
  3.   Response.End()
  4.  Response.Flush()
I'm just going to explain what Shansund was getting at here.
What you need to do is create an ASPX page that will not display a web page. Instead this ASPX page will send the content of the file that you retrieve from your database to the user's.

To do this you need to add an ASPX page to your project and delete any content that is automatically generated.

Make sure you leave the <%@Page ... %> directive at the top of the page (this links to your back end server code)

From there you need to set the page's content type to the file type that you are sending to the person (so that the browser knows what to expect as content since it's not going to be a web page).

Then in your Page Load event you want to retrieve the file from the database and write it to your Response stream (this is sent to the browser) and flush this so that it is sent.

Now in your main ASPX page put a link to the one you just added...when the click the link (or button) it will load the new aspx page and the content will be downloaded.

-Frinny
Sep 29 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mustaq | last post by:
Hi How to get NT User Account, IP and Domain using VB.NET. Thanks, Mustaq
1
by: telescient telescient via .NET 247 | last post by:
(Type your message here) How to transform xml variable to xsl file using asp.net using vb.net -------------------------------- From: telescient telescient ----------------------- Posted by a...
1
by: Christina | last post by:
Hello, I am using ASP.NET (VB.NET) and crystal report. My applications reports runs perfectly in development server. When I move it in production server, and change the database location in...
4
by: raju5725 | last post by:
have a MS access table and I want to export it to comma delimited text file. How do I do this programmatically using VB.NET or C#? Thanks for any help in advance. Raju
0
by: oren18 | last post by:
hello.does anybody know .. how to make an image database by using VB.NET 2005 and Microsoft Access i want to make an application ( VB.NET 2005 ) that prompt a user to put his picture into...
1
by: Mohsin | last post by:
Hi, any one can help me to save visual Basic Data in Access to link through Data control or ODBC. when i am trying to save vb data in Access after making link through data control it is not saving...
5
by: Queez | last post by:
Afternoon, I've spent all morning trawling the net looking for an answer to this. In the end, I've had to resort to good old fashioned asking. How do you determine a file's MIME type using...
1
by: Sagar | last post by:
I want to write a program, that reads and logs the windows events that happened in a particular folder once every minute, 1. A file was created in the folder. which user created ? 2. A file was...
2
by: hemapooja | last post by:
Hi, I am using vb.Net web application. I am getting the error of system.io. ioexception. The process can't access the file because it is being usrd by another process. when file is opened or...
0
by: Jason7899 | last post by:
hi, i try to read and save xml file using vb.net CF any one have a sample that show this for Compaq Framework? i have some samples but for normal framework that simple donīt work in Compaq...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.