Results 1 to 3 of 3

Thread: Code for file upload in VB.net

  1. #1
    BakerJones is offline Senior Member
    Join Date
    Dec 2009
    Posts
    244
    Rep Power
    3

    Default Code for file upload in VB.net

    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.

  2. #2
    AdamsClark is offline Senior Member
    Join Date
    Dec 2009
    Posts
    247
    Rep Power
    3

    Default

    Follow the given code:

    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
    I have tried the given code but it didn’t solve my problem. Please try to give me some other solution.

  3. #3
    AdamsClark is offline Senior Member
    Join Date
    Dec 2009
    Posts
    247
    Rep Power
    3

    Default

    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()

Similar Threads

  1. Asp.net code for download file
    By AllenBrown in forum other peripherals
    Replies: 2
    Last Post: 06-29-2010, 03:33 PM
  2. File Download code in asp.net.
    By HowardAdams in forum Programming
    Replies: 4
    Last Post: 04-03-2010, 12:15 PM
  3. File Download code in asp.net.
    By HowardAdams in forum General Internet Terms
    Replies: 4
    Last Post: 04-03-2010, 12:15 PM
  4. Java code to run batch file
    By RodríguezBrown in forum Programming
    Replies: 3
    Last Post: 03-31-2010, 03:53 PM
  5. How to upload file in asp.net
    By ThomasBarnes in forum Programming
    Replies: 1
    Last Post: 02-09-2010, 04:23 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48