I am doing one website. In that website one form is there in that I want upload the image, document and all other thing. Please tell me Code for file upload in VB.net. Your help would be highly appreciated.
I am doing one website. In that website one form is there in that I want upload the image, document and all other thing. Please tell me Code for file upload in VB.net. Your help would be highly appreciated.
Follow the given code:
I have tried the given code but it didn’t solve my problem. Please try to give me some other solution.Code:protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click If Not fileUpEx.HasFile Is Nothing Then Dim filepath As String = fileUpEx.PostedFile.FileName Dim pat As String = "\(?:.+)\(.+).(.+)" Dim r As Regex = New Regex(pat) 'run Dim m As Match = r.Match(filepath) Dim file_ext As String = m.Groups(2).Captures(0).ToString() Dim filename As String = m.Groups(1).Captures(0).ToString() Dim file As String = filename & "." & file_ext 'save the file to the server fileUpEx.PostedFile.SaveAs(Server.MapPath(".") & file) lblStatus.Text = "File Saved to: " & Server.MapPath(".") & file End If End Sub
In above code I want to upload a file to my project, in the folder resume.
Code:Dim strpath As String = Application.StartupPath Dim num As Integer = strpath.IndexOf("test") strpath = strpath.Remove(num + 7) & "resume" Dim clsRequest As System.Net.FileWebRequest = (System.Net.WebRequest.Create(strpath)) clsRequest.Method = System.Net.WebRequestMethods.File.UploadFile Dim bFile() As Byte = System.IO.File.ReadAllBytes("pathofFile") Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream() clsStream.Write(bFile, 0, bFile.Length) clsStream.Close() clsStream.Dispose()
Bookmarks