About the author

Imran Imran
Like Development in DotNet.

E-mail me Send mail

Recent Articles

 
1: Roles And Membership
Category: ASP.Net
Added: 6/2/2008

 
2: ListView and DataPager in ASP.NET 3.5
Category: ASP.Net
Added: 5/15/2008

 
3: Asp.Net Cookies
Category: ASP.Net
Added: 5/8/2008

 
4: DatagridDatalistRepeater
Category: ASP.Net
Added: 5/8/2008

 
5: mySql With Asp.Net
Category: Databases
Added: 4/16/2008

 
6: MDF without LDF
Category: Databases
Added: 4/16/2008

 
7: Disable Right Click
Category: Java Script
Added: 4/16/2008

 
8: String Functions
Category: ASP.Net
Added: 3/20/2008

 
9: Water Mark
Category: HTML & DHTML
Added: 3/20/2008

 
10: Ajax With Javascript
Category: AJAX
Added: 3/10/2008

Upload file with Asp.Net

by Imran 15/January/2008

Html Code 

<input type=file runat="server" id="myFile1" />

Server Side Code

Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click

Dim file1 As String = ""

file1 = UploadFile(myFile1)

End Sub

Private Function UploadFile(ByVal myfile As HtmlInputFile) As String

Dim file As String = ""

If Not myfile.PostedFile Is Nothing Then

Dim filepath As String = myfile.PostedFile.FileName

If filepath <> "" Then

file = System.IO.Path.GetFileName(myfile.PostedFile.FileName)

Try

myfile.PostedFile.SaveAs(Server.MapPath(".\Files\") & file)Catch ex As Exception

lblErr.Text = ex.Message

End Try

End If

End If

Return file

End Function



Powered by DotNetClassic.com