Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 27th, 2007, 10:06 PM
Registered User
 
Join Date: May 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default PostedFile Error

Hello, I am having a very difficult time trying to upload files to a database. I have read tutorials on this and I have copied and pasted codes from one of them in my aspx page. The code is as follows:

Public Class Upload
    Inherits System.Web.UI.Page
    Protected WithEvents File As System.Web.UI.HtmlControls.HtmlInputFile


 If FileUpload.PostedFile Is Nothing OrElse String.IsNullOrEmpty(FileUpload.PostedFile.FileNam e) OrElse FileUpload.PostedFile.InputStream Is Nothing Then
    ... Show error message ...
    Exit Sub
  End If

  'Make sure we are dealing with a JPG or GIF file
  Dim extension As String = Path.GetExtension(FileUpload.PostedFile.FileName). ToLower()
  Dim MIMEType As String = Nothing

  Select Case extension
    Case ".gif"
      MIMEType = "image/gif"
    Case ".jpg", ".jpeg", ".jpe"
      MIMEType = "image/jpeg"
    Case ".png"
      MIMEType = "image/png"

    Case Else
      'Invalid file type uploaded
      ... Show error message ...
      Exit Sub
  End Select


  'Connect to the database and insert a new record into Products
  Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrin gs("ImageGalleryConnectionString").ConnectionStrin g)

    Const SQL As String = "INSERT INTO [Pictures] ([Title], [MIMEType], [ImageData]) VALUES (@Title, @MIMEType, @ImageData)"
    Dim myCommand As New SqlCommand(SQL, myConnection)
    myCommand.Parameters.AddWithValue("@Title", PictureTitle.Text.Trim())
    myCommand.Parameters.AddWithValue("@MIMEType", MIMEType)

    'Load FileUpload's InputStream into Byte array
    Dim imageBytes(FileUpload.PostedFile.InputStream.Lengt h) As Byte
    FileUpload.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length)
    myCommand.Parameters.AddWithValue("@ImageData", imageBytes)

    myConnection.Open()
    myCommand.ExecuteNonQuery()
    myConnection.Close()
  End Using
End Sub

when I tried to build the solution it says that "PostedFile is not a member of System.Web.UI.WebControl.Button". Also "...Show error ..." caused an error which says "Identifier expected". It also said "Path" is not declared. I don't know what namespace to include in order to make this application work. Thank you in advance for you help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
[Resolved] Error calling a sp - parameter error snufse .NET Framework 2.0 2 February 12th, 2008 04:46 PM
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.