download and upload

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2005
Posts: 4
Reputation: jason_limwk is an unknown quantity at this point 
Solved Threads: 0
jason_limwk jason_limwk is offline Offline
Newbie Poster

download and upload

 
0
  #1
Aug 3rd, 2005
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~
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 514
Reputation: techniner is an unknown quantity at this point 
Solved Threads: 19
techniner techniner is offline Offline
Posting Pro

Re: download and upload

 
0
  #2
Aug 3rd, 2005
Work off this sample:

  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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC