Click here to Skip to main content
15,565,950 members
Articles / Web Development / ASP.NET
Article
Posted 6 Jun 2004

Stats

126.3K views
2.4K downloads
47 bookmarked

FileTransfer Library in VB.NET

Rate me:
Please Sign up or sign in to vote.
3.08/5 (20 votes)
6 Jun 20042 min read
This class is designed to upload and download files via browser through asp.net and vb.net

License

Free to use and modify as long as header stays in place.

Terms and Conditions

For Use, Copy, Distribution and Modification: THIS CODE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS CODE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

How to use

Compile code into a .net dll assembly and put into your website home (bin) folder. Also transfer Interop.Scripting.dll and adodb.dll into your bin folder also.

Permissions

Make sure your permissions are correctly set for whatever folder you are writing or reading from.

Code For Download

VB.NET
<%@ Import Namespace = "FileTransfer.FileTransfer"%> 
<script language="VB"runat=server>
Sub Page_Load(Sender As Object, E As EventArgs)
  If Not (Page.IsPostBack)
    Dim rs as New File
    Dim Downloads as string = rs.Download("test.txt", "c:/", 100000)
    'Dim Downloads as string = rs.Download(Request.querystring
    '("Link"), "c:/", 100000)
  End If
End Sub
</script>

Code For Upload

VB.NET
<%@ Import Namespace = "FileTransfer.FileTransfer"%> 
<script language="VB"runat=server>
Sub Upload_File (Sender as Object, e as EventArgs)
  Dim FileControl as System.Web.UI.HtmlControls.HtmlInputFile = MyFile
  Dim rs as New File()
  Dim ReturnMessage as String = rs.Upload("c:\", FileControl) 

  Context.response.write(ReturnMessage)
End Sub
</script>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Upload File</title>
<meta http-equiv="Content-Type"content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="upload.aspx"method="post"enctype="Multipart/Form-Data"runat="server">
<input id="MyFile"type="File"runat="Server"size="25">
<br><br><asp:button ID="SubmitButton"text="Upload"runat="server"
   OnClick="Upload_File"style="cursor:hand; 
   background-color: #0000A0; color: #ffffff;"/>
</form>
</body>
</html>

Details

Well lets see here, do you think you have had enough of file transfer via browser. I don't think so! But wait hold up don't leave just yet. My

FileTransfer
class has a different approach to the whole thing. Lets get started. My download function uses both adodb and Interop.Scripting to allow files to be downloaded in chunks. Yes! chunks of byte data that you can specify the size of. This allows you to surpass the 4mb cache limit for downloads via browser. I also designed the download function to force the browser to download the file by setting the
ContentType 
="application/octet-stream"
. I use adodb to make a binary stream of the file. From there I loop through pulling the allotted chunk sizes and flush the stream on each pass making sure the data never overwhelms the cache size. When the data has finished sending, I check to see if there is left over data to be sent, that maybe wasn't a full block size. I send that data also to complete the download.

My upload function is not as special. It uses the common way Microsoft explains on how to do it. I could have easily made it using the same philosophy as the download function, to give me more control. But both ways are possibly. I am tired now so I am going to finish with that. If anyone needs any help let me know. I am going to sleep now. LOL

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Codevendor
United States United States
Please visit my personal website https://codevendor.com for my latest codes and updates.

Comments and Discussions

 
QuestionNew to .DLL file usage Pin
Michael Grumbach5-Jul-11 4:23
Michael Grumbach5-Jul-11 4:23 
QuestionWhat's the max size ? Pin
powerkru7-Mar-08 5:25
powerkru7-Mar-08 5:25 
Generalautodownload and autoupload [modified] Pin
amitcoder8310-Jul-06 2:21
amitcoder8310-Jul-06 2:21 
GeneralWeb server relative path Pin
gchq30-May-06 15:47
gchq30-May-06 15:47 
GeneralUnable to download file Pin
Venu_9330-May-06 9:25
Venu_9330-May-06 9:25 
GeneralUpload jpg Pin
Vitoto18-Oct-05 7:08
Vitoto18-Oct-05 7:08 
GeneralRe: Upload jpg Pin
Kamal Sidhu3-May-06 19:06
Kamal Sidhu3-May-06 19:06 
GeneralStalls on Large Files Pin
jtclayton23-Jun-05 13:53
jtclayton23-Jun-05 13:53 
GeneralRe: Stalls on Large Files Pin
M@dHatter23-Jun-05 14:09
M@dHatter23-Jun-05 14:09 
GeneralRe: Stalls on Large Files Pin
jtclayton23-Jun-05 14:22
jtclayton23-Jun-05 14:22 
GeneralRe: Stalls on Large Files Pin
jtclayton23-Jun-05 14:16
jtclayton23-Jun-05 14:16 
GeneralRe: Stalls on Large Files Pin
M@dHatter23-Jun-05 14:23
M@dHatter23-Jun-05 14:23 
GeneralRe: Stalls on Large Files Pin
jtclayton23-Jun-05 14:44
jtclayton23-Jun-05 14:44 
GeneralRe: Stalls on Large Files Pin
Kamal Sidhu3-May-06 19:15
Kamal Sidhu3-May-06 19:15 
AnswerRe: Stalls on Large Files Pin
metweek22-Feb-07 6:39
metweek22-Feb-07 6:39 
GeneralThanks workse nice :) Pin
Member 16415389-Jan-05 8:22
Member 16415389-Jan-05 8:22 
GeneralProblem with downloading arabic named file.. Pin
khurram rathor19-Oct-04 2:29
khurram rathor19-Oct-04 2:29 
GeneralThanks Pin
Todd Smith3-Sep-04 12:41
Todd Smith3-Sep-04 12:41 
GeneralThis actually is a good article Pin
tjohnson7110-Jun-04 6:10
tjohnson7110-Jun-04 6:10 
GeneralRe: This actually is a good article Pin
M@dHatter10-Jun-04 10:54
M@dHatter10-Jun-04 10:54 
GeneralRe: There's a reason... Pin
robtherat0068-Jun-04 0:35
sussrobtherat0068-Jun-04 0:35 
GeneralRe: There's a reason... Pin
M@dHatter8-Jun-04 10:53
M@dHatter8-Jun-04 10:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.