Click here to Skip to main content
Click here to Skip to main content
Go to top

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>

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

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.

Comments and Discussions

 
QuestionNew to .DLL file usage PinmemberMichael Grumbach5-Jul-11 3:23 
QuestionWhat's the max size ? Pinmemberpowerkru7-Mar-08 4:25 
Generalautodownload and autoupload [modified] Pinmemberamitcoder8310-Jul-06 1:21 
GeneralWeb server relative path Pinmembergchq30-May-06 14:47 
GeneralUnable to download file PinmemberVenu_9330-May-06 8:25 
GeneralUpload jpg PinmemberVitoto18-Oct-05 6:08 
GeneralRe: Upload jpg PinmemberKamal Sidhu3-May-06 18:06 
GeneralStalls on Large Files Pinmemberjtclayton23-Jun-05 12:53 
GeneralRe: Stalls on Large Files PinmemberVectorX23-Jun-05 13:09 
GeneralRe: Stalls on Large Files Pinmemberjtclayton23-Jun-05 13:22 
GeneralRe: Stalls on Large Files Pinmemberjtclayton23-Jun-05 13:16 
GeneralRe: Stalls on Large Files PinmemberVectorX23-Jun-05 13:23 
GeneralRe: Stalls on Large Files Pinmemberjtclayton23-Jun-05 13:44 
GeneralRe: Stalls on Large Files PinmemberKamal Sidhu3-May-06 18:15 
AnswerRe: Stalls on Large Files Pinmembermetweek22-Feb-07 5:39 
GeneralThanks workse nice :) PinmemberN3XuS9-Jan-05 7:22 
GeneralProblem with downloading arabic named file.. Pinmemberkhurram rathor19-Oct-04 1:29 
GeneralThanks PinmemberTodd Smith3-Sep-04 11:41 
GeneralThis actually is a good article Pinmembertjohnson7110-Jun-04 5:10 
GeneralRe: This actually is a good article PinmemberVectorX10-Jun-04 9:54 
GeneralRe: There's a reason... Pinsussrobtherat0067-Jun-04 23:35 
GeneralRe: There's a reason... PinmemberVectorX8-Jun-04 9:53 

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.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 7 Jun 2004
Article Copyright 2004 by M@dHatter
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid