Click here to Skip to main content
Licence 
First Posted 6 Jun 2004
Views 96,557
Downloads 1,037
Bookmarked 47 times

FileTransfer Library in VB.NET

By | 6 Jun 2004 | Article
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

<%@ 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

<%@ 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

About the Author

VectorX

Software Developer (Senior)
Codevendor
United States United States

Member

Please visit my personal website http://www.codevendor.com for my latest codes and updates.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionNew to .DLL file usage PinmemberMichael Grumbach3:23 5 Jul '11  
QuestionWhat's the max size ? Pinmemberpowerkru4:25 7 Mar '08  
Generalautodownload and autoupload [modified] Pinmemberamitcoder831:21 10 Jul '06  
GeneralWeb server relative path Pinmembergchq14:47 30 May '06  
GeneralUnable to download file PinmemberVenu_938:25 30 May '06  
GeneralUpload jpg PinmemberVitoto6:08 18 Oct '05  
Hi, i have VB.Net client/Server Program.
 
This code work for me in upload jpg file to server ?
 
Thank you.
GeneralRe: Upload jpg PinmemberKamal Sidhu18:06 3 May '06  
GeneralStalls on Large Files Pinmemberjtclayton12:53 23 Jun '05  
GeneralRe: Stalls on Large Files PinmemberVectorX13:09 23 Jun '05  
GeneralRe: Stalls on Large Files Pinmemberjtclayton13:22 23 Jun '05  
GeneralRe: Stalls on Large Files Pinmemberjtclayton13:16 23 Jun '05  
GeneralRe: Stalls on Large Files PinmemberVectorX13:23 23 Jun '05  
GeneralRe: Stalls on Large Files Pinmemberjtclayton13:44 23 Jun '05  
GeneralRe: Stalls on Large Files PinmemberKamal Sidhu18:15 3 May '06  
AnswerRe: Stalls on Large Files Pinmembermetweek5:39 22 Feb '07  
GeneralThanks workse nice :) PinmemberN3XuS7:22 9 Jan '05  
GeneralProblem with downloading arabic named file.. Pinmemberkhurram rathor1:29 19 Oct '04  
GeneralThanks PinmemberTodd Smith11:41 3 Sep '04  
GeneralThis actually is a good article Pinmembertjohnson715:10 10 Jun '04  
GeneralRe: This actually is a good article PinmemberVectorX9:54 10 Jun '04  
GeneralRe: There's a reason... Pinsussrobtherat00623:35 7 Jun '04  
GeneralRe: There's a reason... PinmemberVectorX9:53 8 Jun '04  

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

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120529.1 | Last Updated 7 Jun 2004
Article Copyright 2004 by VectorX
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid