Show and Upload an image

Discussion in 'ASP .Net Web Controls' started by sameer, Feb 15, 2005.

  1. sameer

    sameer Guest

    Hi, i am new to asp.net.
    From the web page I want to give the user option to browse on the local file
    system and select an image file, when the user selects this image file, i
    want to show the image to the user in the asp page. Then when the use clicks
    on submit, i want to upload this image along with the other text fields on
    the same page( which the user will enter) . In asp 3 days there used to be
    3rd prty controls to do this, how is it possible in ASP.net ?

    if showing the image before uploading become a big deal , i dont mind
    skipping that step but would definetly want to upload the image.

    thanks
    Sameer
    sameer, Feb 15, 2005
    #1
    1. Advertising

  2. sameer

    Gold Guest

    Hi,

    it's simle, but there is no web form file control, so you have to use the
    file control available under HTML controls. and set the runat property of
    that control to server.
    In your button event use the following statement to get the uploaded file
    details
    (assume the control is named as fileCntrl)

    fileCntrl.PostedFile.FileName -- gives you the selected file name
    *place a image control in your page and assign this filename to the
    src
    property of the control at run time, to show the image before
    uploading

    fileCntrl.PostedFile.FileStream -- gives you the stream obj ref, so u can
    read the contents of the file, and store it into a DB or folder, whatever way
    you want.


    Regards,
    :) Thangam


    "sameer" wrote:

    > Hi, i am new to asp.net.
    > From the web page I want to give the user option to browse on the local file
    > system and select an image file, when the user selects this image file, i
    > want to show the image to the user in the asp page. Then when the use clicks
    > on submit, i want to upload this image along with the other text fields on
    > the same page( which the user will enter) . In asp 3 days there used to be
    > 3rd prty controls to do this, how is it possible in ASP.net ?
    >
    > if showing the image before uploading become a big deal , i dont mind
    > skipping that step but would definetly want to upload the image.
    >
    > thanks
    > Sameer
    Gold, Feb 16, 2005
    #2
    1. Advertising

  3. sameer

    sameer Guest

    thanks Gold, will try it .
    Sameer

    "Gold" wrote:

    >
    > Hi,
    >
    > it's simle, but there is no web form file control, so you have to use the
    > file control available under HTML controls. and set the runat property of
    > that control to server.
    > In your button event use the following statement to get the uploaded file
    > details
    > (assume the control is named as fileCntrl)
    >
    > fileCntrl.PostedFile.FileName -- gives you the selected file name
    > *place a image control in your page and assign this filename to the
    > src
    > property of the control at run time, to show the image before
    > uploading
    >
    > fileCntrl.PostedFile.FileStream -- gives you the stream obj ref, so u can
    > read the contents of the file, and store it into a DB or folder, whatever way
    > you want.
    >
    >
    > Regards,
    > :) Thangam
    >
    >
    > "sameer" wrote:
    >
    > > Hi, i am new to asp.net.
    > > From the web page I want to give the user option to browse on the local file
    > > system and select an image file, when the user selects this image file, i
    > > want to show the image to the user in the asp page. Then when the use clicks
    > > on submit, i want to upload this image along with the other text fields on
    > > the same page( which the user will enter) . In asp 3 days there used to be
    > > 3rd prty controls to do this, how is it possible in ASP.net ?
    > >
    > > if showing the image before uploading become a big deal , i dont mind
    > > skipping that step but would definetly want to upload the image.
    > >
    > > thanks
    > > Sameer
    sameer, Feb 16, 2005
    #3
  4. sameer

    sameer Guest

    Hey Gold, i got stuck again and this is where it is

    when i click on the file control browse and select an image, i want the user
    to see the image in the image Box but the file control does not have any
    event at the server which fires where i select an image in it, any ideas how
    i can do this.?

    "sameer" wrote:

    > thanks Gold, will try it .
    > Sameer
    >
    > "Gold" wrote:
    >
    > >
    > > Hi,
    > >
    > > it's simle, but there is no web form file control, so you have to use the
    > > file control available under HTML controls. and set the runat property of
    > > that control to server.
    > > In your button event use the following statement to get the uploaded file
    > > details
    > > (assume the control is named as fileCntrl)
    > >
    > > fileCntrl.PostedFile.FileName -- gives you the selected file name
    > > *place a image control in your page and assign this filename to the
    > > src
    > > property of the control at run time, to show the image before
    > > uploading
    > >
    > > fileCntrl.PostedFile.FileStream -- gives you the stream obj ref, so u can
    > > read the contents of the file, and store it into a DB or folder, whatever way
    > > you want.
    > >
    > >
    > > Regards,
    > > :) Thangam
    > >
    > >
    > > "sameer" wrote:
    > >
    > > > Hi, i am new to asp.net.
    > > > From the web page I want to give the user option to browse on the local file
    > > > system and select an image file, when the user selects this image file, i
    > > > want to show the image to the user in the asp page. Then when the use clicks
    > > > on submit, i want to upload this image along with the other text fields on
    > > > the same page( which the user will enter) . In asp 3 days there used to be
    > > > 3rd prty controls to do this, how is it possible in ASP.net ?
    > > >
    > > > if showing the image before uploading become a big deal , i dont mind
    > > > skipping that step but would definetly want to upload the image.
    > > >
    > > > thanks
    > > > Sameer
    sameer, Feb 16, 2005
    #4
  5. sameer

    Gold Guest

    Hi,

    there is no direct way to do this, still you can get the same behaviour
    using client side scripts. The file control raises a client side event
    whenever there is a change in any of the property, so when a file is
    selected, the selected filename is assigned to the value property of the
    control, which automatically causes the event to fire. Within this event
    routine (written in javascript) you can get the file name and assign it to
    the image control. One nice thing is that, everything is performed without a
    postback....Try this

    :)
    Thangam

    "sameer" wrote:

    > Hey Gold, i got stuck again and this is where it is
    >
    > when i click on the file control browse and select an image, i want the user
    > to see the image in the image Box but the file control does not have any
    > event at the server which fires where i select an image in it, any ideas how
    > i can do this.?
    >
    > "sameer" wrote:
    >
    > > thanks Gold, will try it .
    > > Sameer
    > >
    > > "Gold" wrote:
    > >
    > > >
    > > > Hi,
    > > >
    > > > it's simle, but there is no web form file control, so you have to use the
    > > > file control available under HTML controls. and set the runat property of
    > > > that control to server.
    > > > In your button event use the following statement to get the uploaded file
    > > > details
    > > > (assume the control is named as fileCntrl)
    > > >
    > > > fileCntrl.PostedFile.FileName -- gives you the selected file name
    > > > *place a image control in your page and assign this filename to the
    > > > src
    > > > property of the control at run time, to show the image before
    > > > uploading
    > > >
    > > > fileCntrl.PostedFile.FileStream -- gives you the stream obj ref, so u can
    > > > read the contents of the file, and store it into a DB or folder, whatever way
    > > > you want.
    > > >
    > > >
    > > > Regards,
    > > > :) Thangam
    > > >
    > > >
    > > > "sameer" wrote:
    > > >
    > > > > Hi, i am new to asp.net.
    > > > > From the web page I want to give the user option to browse on the local file
    > > > > system and select an image file, when the user selects this image file, i
    > > > > want to show the image to the user in the asp page. Then when the use clicks
    > > > > on submit, i want to upload this image along with the other text fields on
    > > > > the same page( which the user will enter) . In asp 3 days there used to be
    > > > > 3rd prty controls to do this, how is it possible in ASP.net ?
    > > > >
    > > > > if showing the image before uploading become a big deal , i dont mind
    > > > > skipping that step but would definetly want to upload the image.
    > > > >
    > > > > thanks
    > > > > Sameer
    Gold, Feb 18, 2005
    #5
  6. sameer

    Gold Guest

    Hey, I am sorry I forget to tell you the name of the event it's

    onpropertychange

    so, your code should look like the following

    <input type="file" id="selectfile" onpropertychange="displayimage();"
    runat="server">

    //Thangam

    "Gold" wrote:

    > Hi,
    >
    > there is no direct way to do this, still you can get the same behaviour
    > using client side scripts. The file control raises a client side event
    > whenever there is a change in any of the property, so when a file is
    > selected, the selected filename is assigned to the value property of the
    > control, which automatically causes the event to fire. Within this event
    > routine (written in javascript) you can get the file name and assign it to
    > the image control. One nice thing is that, everything is performed without a
    > postback....Try this
    >
    > :)
    > Thangam
    >
    > "sameer" wrote:
    >
    > > Hey Gold, i got stuck again and this is where it is
    > >
    > > when i click on the file control browse and select an image, i want the user
    > > to see the image in the image Box but the file control does not have any
    > > event at the server which fires where i select an image in it, any ideas how
    > > i can do this.?
    > >
    > > "sameer" wrote:
    > >
    > > > thanks Gold, will try it .
    > > > Sameer
    > > >
    > > > "Gold" wrote:
    > > >
    > > > >
    > > > > Hi,
    > > > >
    > > > > it's simle, but there is no web form file control, so you have to use the
    > > > > file control available under HTML controls. and set the runat property of
    > > > > that control to server.
    > > > > In your button event use the following statement to get the uploaded file
    > > > > details
    > > > > (assume the control is named as fileCntrl)
    > > > >
    > > > > fileCntrl.PostedFile.FileName -- gives you the selected file name
    > > > > *place a image control in your page and assign this filename to the
    > > > > src
    > > > > property of the control at run time, to show the image before
    > > > > uploading
    > > > >
    > > > > fileCntrl.PostedFile.FileStream -- gives you the stream obj ref, so u can
    > > > > read the contents of the file, and store it into a DB or folder, whatever way
    > > > > you want.
    > > > >
    > > > >
    > > > > Regards,
    > > > > :) Thangam
    > > > >
    > > > >
    > > > > "sameer" wrote:
    > > > >
    > > > > > Hi, i am new to asp.net.
    > > > > > From the web page I want to give the user option to browse on the local file
    > > > > > system and select an image file, when the user selects this image file, i
    > > > > > want to show the image to the user in the asp page. Then when the use clicks
    > > > > > on submit, i want to upload this image along with the other text fields on
    > > > > > the same page( which the user will enter) . In asp 3 days there used to be
    > > > > > 3rd prty controls to do this, how is it possible in ASP.net ?
    > > > > >
    > > > > > if showing the image before uploading become a big deal , i dont mind
    > > > > > skipping that step but would definetly want to upload the image.
    > > > > >
    > > > > > thanks
    > > > > > Sameer
    Gold, Feb 18, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Heather Fraser
    Replies:
    0
    Views:
    620
    Heather Fraser
    Jul 5, 2004
  2. Joe
    Replies:
    0
    Views:
    661
  3. Disco Octopus

    to show image or to show flash

    Disco Octopus, May 13, 2004, in forum: HTML
    Replies:
    7
    Views:
    2,419
    Toby A Inkster
    May 14, 2004
  4. =?Utf-8?B?am9l?=
    Replies:
    2
    Views:
    3,386
    Winista
    Jul 24, 2006
  5. handersonVA

    clicking small image to show a big image

    handersonVA, Nov 28, 2005, in forum: Javascript
    Replies:
    6
    Views:
    456
    Thomas 'PointedEars' Lahn
    Dec 1, 2005
Loading...

Share This Page