473,725 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

28 New Member
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 2527
shansund
3 New Member
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 Recognized Expert Moderator Expert
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
3557
by: Mustaq | last post by:
Hi How to get NT User Account, IP and Domain using VB.NET. Thanks, Mustaq
1
1148
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 user from .NET 247 (http://www.dotnet247.com/) <Id>GMw7Mw5svEKqOpjKBwHbtQ==</Id>
1
1284
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 web.config file it does not function as its supposed to. Any idea, whats going on wrong ? TIA,
4
8190
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
1268
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 database (Mic. Access) the database i've set have a pictures field , staff name , address and so on.. so in the VB i know how to build a connection to the database ..
1
3113
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 what is reason i donot know. suppose i made one table in access and save in my Document and design a form in vb with same data field and make a link through data control properties so what will i write on save button to save those data in...
5
21056
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 VB.NET? The problem is: - I have an ASP.NET web application - I can display a list of all files in a directory on the server (it's a "directory share" for a scanner) - I want the user to be able to select one of the files to import into the...
1
1824
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 updated in the folder, which user updated ? 3. A file was deleted from the folder, which user deleted ? My question is, Is it possible to read the instance and info of the above said 'windows events' using vb.net ?
2
1196
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 not the file should be deleted from the path Need the solution for this issue.
0
1081
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 Framework. thanks a lot for your help :)
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9174
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.