944,121 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 4756
  • ASP.NET RSS
Aug 3rd, 2005
0

download and upload

Expand Post »
now iam doing a photo gallery in my site...(aspx in vb.net)
and i got some sample coding but mostly are in C#....recentuly i being redirected to a sample page and yupe// it looks good for me..~ but i am just wondering how can i do an upload function in my aspx (vb.net)?
the coding is too long for me to paste here..
but i am trying to say.. how to do in aspx (vb.net coding) when admin click a browse button... it will browse and then select and upload it to my /images/... and the the view.aspx will display the photo?

something like upload and download function? can anyone help ? thanks....

if you nid to email me.. i am available at any time... jasonlimwk@gmail.com

thanks for the help~
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jason_limwk is offline Offline
4 posts
since Aug 2005
Aug 3rd, 2005
0

Re: download and upload

Work off this sample:

ASP.NET Syntax (Toggle Plain Text)
  1. Sub btnUpload_Click (Sender as Object, e as EventArgs)
  2.  
  3. If Not (ctlFileImage.Posted is Nothing) Then
  4.  
  5.  
  6.  
  7. With ctlFileImage.Posted
  8.  
  9.  
  10.  
  11. Dim lngFileSize as Long = .ContentLength ‘//Size in Bytes upload file
  12.  
  13. Dim sContentType as String = .ContentType ‘//Returned by MINE type
  14.  
  15. Dim sFileName as String =.FileName ‘//Client File Name and Path
  16.  
  17.  
  18.  
  19. ‘//Size Check if you do not require it then comment the following if
  20.  
  21. If (lngFileSize / 1024) > 10 Then ‘// If file size is over 10Kb
  22.  
  23. lblError.Caption += “File Size Too Much {:-o�
  24.  
  25. lblError.Visible = True
  26.  
  27. Exit Sub
  28.  
  29. End If
  30.  
  31.  
  32.  
  33. ‘//File Type Filteration: add any type and add the code to you specific type
  34.  
  35. Select Case Trim (sContentType.ToLower)
  36.  
  37.  
  38.  
  39. ‘// Filter the file types that are sent by the browser
  40.  
  41. Case "image/gif", "image/pjpg", "image/jpeg", "image/pjpeg", "image/jpg"
  42.  
  43. Try
  44.  
  45.  
  46.  
  47. ‘// Save the file to the server if you cannot save it then see the Errors ‘//Details Section below almost at end of the article
  48.  
  49.  
  50.  
  51. ‘//Get only filename.ext by using IO Class no path as we use our own path
  52.  
  53. sFileName = System.IO.Path.GetFileName (.FileName)
  54.  
  55.  
  56.  
  57. .SaveAs (Server.MapPath (“/project/users_imgs/�) & sFilename)
  58.  
  59.  
  60.  
  61. ‘// you can also code here to store this picture in SQL server rather ‘// than saving on the server
  62.  
  63. ‘// That will be my next version of this article :-)
  64.  
  65.  
  66.  
  67. ‘// Now file is uploaded but what about the description of the picture.
  68.  
  69. ‘// in ASP.NET all the controls persist their values in the server round
  70.  
  71. ‘// cycles so you donot worry about the value of txtDesc it will be
  72.  
  73. ‘// there as normal. So you can now use the txtDesc.Text and image
  74.  
  75. ‘// path to store in the databse
  76.  
  77.  
  78.  
  79. Dim conn as New System.Data.SqlClient.SqlConnection (Your Connection String)
  80.  
  81. Dim cmd as New System.Data.SqlClient.SqlCommand
  82.  
  83.  
  84.  
  85. With cmd
  86.  
  87. .CommandText = “your update or insert query that use txtDesc.Text and other controls�
  88.  
  89. .Connection = conn
  90.  
  91. .CommandType = CommandType.Text
  92.  
  93. If Conn.State = ConnectionState.Closed Then Conn.Open ()
  94.  
  95. .ExecuteNonQuery ()
  96.  
  97. End With
  98.  
  99.  
  100.  
  101. Catch ex As Exception
  102.  
  103. lblError.Caption += ex.ToString
  104.  
  105. lblError.Visible = True
  106.  
  107. Exit Sub
  108.  
  109. End Try
  110.  
  111.  
  112.  
  113. Case Else
  114.  
  115. lblError.Caption += “Invalid File Type Only Pictured are required.�
  116.  
  117. lblError.Visible = True
  118.  
  119. Exit Sub
  120.  
  121.  
  122.  
  123. End Select
  124.  
  125.  
  126.  
  127. End With
  128.  
  129.  
  130.  
  131. End Sub
Reputation Points: 12
Solved Threads: 19
Posting Pro
techniner is offline Offline
521 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: about confirm message box
Next Thread in ASP.NET Forum Timeline: email button in mail.body





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC