Create directory and file upload control

27 Nov

This is a control that first create a physical path and after let you use it as upload to anywhere in the web server for files of any extension.

Important : This was done with this web reference.

http://www.aspnettutorials.com/tutorials/file/

Amazing place to learn ASP.NET.  It’s free, but accepts the donations for the continuity of the project.

Sorry the designer part of the code wordpress not permit me to include in the post, after a couple of intents was not possible.

It easy to create.  In 2 minutes you can see it running.

1.create_uploadCTRL.ascx.

2.add 1 textbox, 1 file upload control, 1 button

3.put the the next code in the file .vb

create_uploadCTRL.ascx.vb (filename)

(code begin)

Imports System.IO

Partial Class create_uploadCTRL

Inherits System.Web.UI.UserControl

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

Try

Directory.CreateDirectory(MapPath(“.”) & “\” & txtDir.Text)

Catch ex As Exception

lblStatus.Text = ex.Message

End Try

If myFileUpload.HasFile Then

‘myFileUpload.SaveAs(Server.MapPath(“.”) & “\” & txtDir.Text & myFileUpload.FileName)

myFileUpload.SaveAs(Server.MapPath(“.”) & “\” & txtDir.Text & “\” & myFileUpload.FileName)

End If

End Sub

End Class

(code end)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: