Click here to Skip to main content
12,405,543 members (63,340 online)
Click here to Skip to main content
Add your own
alternative version

Stats

108.7K views
2K downloads
47 bookmarked
Posted

FileTransfer Library in VB.NET

, 6 Jun 2004
Rate this:
Please Sign up or sign in to vote.
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>

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 FileTransferclass 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

Share

About the Author

M@dHatter
Software Developer (Senior) Codevendor
United States United States
Please visit my personal website http://www.codevendor.com for my latest codes and updates.

Raise Bid

You may also be interested in...

Comments and Discussions

 
QuestionNew to .DLL file usage Pin
Michael Grumbach5-Jul-11 3:23
memberMichael Grumbach5-Jul-11 3:23 
QuestionWhat's the max size ? Pin
powerkru7-Mar-08 4:25
memberpowerkru7-Mar-08 4:25 
Generalautodownload and autoupload [modified] Pin
amitcoder8310-Jul-06 1:21
memberamitcoder8310-Jul-06 1:21 
GeneralWeb server relative path Pin
gchq30-May-06 14:47
membergchq30-May-06 14:47 
GeneralUnable to download file Pin
Venu_9330-May-06 8:25
memberVenu_9330-May-06 8:25 
GeneralUpload jpg Pin
Vitoto18-Oct-05 6:08
memberVitoto18-Oct-05 6:08 
GeneralRe: Upload jpg Pin
Kamal Sidhu3-May-06 18:06
memberKamal Sidhu3-May-06 18:06 
GeneralStalls on Large Files Pin
jtclayton23-Jun-05 12:53
memberjtclayton23-Jun-05 12:53 
GeneralRe: Stalls on Large Files Pin
VectorX23-Jun-05 13:09
memberVectorX23-Jun-05 13:09 
GeneralRe: Stalls on Large Files Pin
jtclayton23-Jun-05 13:22
memberjtclayton23-Jun-05 13:22 
GeneralRe: Stalls on Large Files Pin
jtclayton23-Jun-05 13:16
memberjtclayton23-Jun-05 13:16 
GeneralRe: Stalls on Large Files Pin
VectorX23-Jun-05 13:23
memberVectorX23-Jun-05 13:23 
GeneralRe: Stalls on Large Files Pin
jtclayton23-Jun-05 13:44
memberjtclayton23-Jun-05 13:44 
GeneralRe: Stalls on Large Files Pin
Kamal Sidhu3-May-06 18:15
memberKamal Sidhu3-May-06 18:15 
AnswerRe: Stalls on Large Files Pin
metweek22-Feb-07 5:39
membermetweek22-Feb-07 5:39 
GeneralThanks workse nice :) Pin
N3XuS9-Jan-05 7:22
memberN3XuS9-Jan-05 7:22 
GeneralProblem with downloading arabic named file.. Pin
khurram rathor19-Oct-04 1:29
memberkhurram rathor19-Oct-04 1:29 
GeneralThanks Pin
Todd Smith3-Sep-04 11:41
memberTodd Smith3-Sep-04 11:41 
GeneralThis actually is a good article Pin
tjohnson7110-Jun-04 5:10
membertjohnson7110-Jun-04 5:10 
GeneralRe: This actually is a good article Pin
VectorX10-Jun-04 9:54
memberVectorX10-Jun-04 9:54 
GeneralRe: There's a reason... Pin
robtherat0067-Jun-04 23:35
sussrobtherat0067-Jun-04 23:35 
GeneralRe: There's a reason... Pin
VectorX8-Jun-04 9:53
memberVectorX8-Jun-04 9: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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160721.1 | Last Updated 7 Jun 2004
Article Copyright 2004 by M@dHatter
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid