uploading pictures

Discussion in 'ASP .Net' started by Jeff, Mar 25, 2009.

  1. Jeff

    Jeff Guest

    hi

    asp.net 2.0

    I'm creating a webpage where admin can write articles and upload pictures
    associated with that article. There can be n pictures. So the pictures need
    to be stored in a separated table with foreign key to the article table

    So I thought I about put an FileUpload control on the page, together with an
    upload button. When clicking on the upload button the picture is "uploaded"
    but not yet stored on the server. In addition I want a Repeater control on
    the page to display a thumbnail of the picture after it's been "uploaded",
    so that admin can see which pictures are uploaded and discard a picture if
    he feels like doing that...

    When admin save the article, the uploaded pictures are stored in the
    database...

    I'm unsure how to do this. More specifically I'm unsure how to store
    pictures in the database. I mean the page has just some thumbnails to the
    pictures... not sure how to save the fullsize to the database... maybe I
    need to hold an array of streams, streams to each picture...

    any suggestions?
    Jeff, Mar 25, 2009
    #1
    1. Advertising

  2. On Mar 25, 2:11 pm, "Jeff" <> wrote:
    > hi
    >
    > asp.net 2.0
    >
    > I'm creating a webpage where admin can write articles and upload pictures
    > associated with that article. There can be n pictures. So the pictures need
    > to be stored in a separated table with foreign key to the article table
    >
    > So I thought I about put an FileUpload control on the page, together with an
    > upload button. When clicking on the upload button the picture is "uploaded"
    > but not yet stored on the server. In addition I want a Repeater control on
    > the page to display a thumbnail of the picture after it's been "uploaded",
    > so that admin can see which pictures are uploaded and discard a picture if
    > he feels like doing that...
    >
    > When admin save the article, the uploaded pictures are stored in the
    > database...
    >
    > I'm unsure how to do this. More specifically I'm unsure how to store
    > pictures in the database. I mean the page has just some thumbnails to the
    > pictures... not sure how to save the fullsize to the database... maybe I
    > need to hold an array of streams, streams to each picture...
    >
    > any suggestions?


    Check this first
    http://www.google.com/search?q=asp.net pictures in the database
    Alexey Smirnov, Mar 25, 2009
    #2
    1. Advertising

  3. Jeff

    Jeff Guest

    thanks for the link

    I think I create a custom class which holds these values from the FileUpload
    control:
    FileUpload .FileName,
    FileUpload .PostedFile.ContentLength,
    FileUpload .FileBytes,
    FileUpload .PostedFile.ContentType

    Then declare an generic list, for example List<Picture> picture which for
    each time I upload a picture I add that picture to this generic list. and
    then I can also use this generic list as datasource for the repeater
    control... when admin saves the article, I send this generic list as an
    input parameter into that article and then saves those pictures belonging to
    that article...

    Unsure if the generic list holds the data between postbacks and stuff like
    that.. so I'll give it a try and see what I discover...

    any suggestions are most welcome
    Jeff, Mar 25, 2009
    #3
  4. Jeff

    Jeff Guest

    as I was fearing, the generic list didn't hold it's values between
    postbacks... Here is my code:

    public partial class _Default : System.Web.UI.Page
    {

    List<Picture> pictures = new List<Picture>();

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void lbUpload_Command(object sender, CommandEventArgs e)
    {
    if (FileUpload1.HasFile)
    {
    Picture picture = new Picture(FileUpload1.FileName,
    FileUpload1.PostedFile.ContentLength,
    FileUpload1.FileBytes,
    FileUpload1.PostedFile.ContentType);
    pictures.Add(picture);
    }
    }


    }

    any suggestions/comments are most welcome
    Jeff, Mar 25, 2009
    #4
  5. Jeff

    Jeff Guest

    I'm looking up viewstate in the documentation now....
    Jeff, Mar 25, 2009
    #5
  6. Jeff

    Jeff Guest

    I think storing an generic list of pictures in viewstate is too much, think
    it will make the page terrible slow :(

    now looking for alternatives....


    "Jeff" <> wrote in message
    news:...
    > I'm looking up viewstate in the documentation now....
    >
    Jeff, Mar 25, 2009
    #6
  7. On Mar 25, 9:41 pm, "Jeff" <> wrote:
    > thanks for the link
    >
    > I think I create a custom class which holds these values from the FileUpload
    > control:
    > FileUpload .FileName,
    > FileUpload .PostedFile.ContentLength,
    > FileUpload .FileBytes,
    > FileUpload .PostedFile.ContentType
    >
    > Then declare an generic list, for example List<Picture> picture which for
    > each time I upload a picture I add that picture to this generic list. and
    > then I can also use this generic list as datasource for the repeater
    > control... when admin saves the article, I send this generic list as an
    > input parameter into that article and then saves those pictures belonging to
    > that article...
    >
    > Unsure if the generic list holds the data between postbacks and stuff like
    > that.. so I'll give it a try and see what I discover...
    >
    > any suggestions are most welcome


    If I were you I would use a database for this. You already uploaded a
    files to the database. Say, you have a table

    ArticleID
    FileName
    ContentLength
    FileBytes
    ContentType
    ImageData

    where ArticleID is an id of the article images belong to. Use that
    table as a datasource for the repeater control

    SELECT FileName, ... FROM Table1 WHERE ArticleID=1234

    If article was not uploaded yet, you can create a record in the
    database for this (to get an ArticleID) once the first image was
    attached. In this case you maybe would need to have a status field to
    identify Active/Non-active articles

    ArticleID
    ArticleName
    ArticleText
    Status
    Alexey Smirnov, Mar 26, 2009
    #7
    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. beethovenofear

    uploading pictures

    beethovenofear, Apr 23, 2006, in forum: HTML
    Replies:
    4
    Views:
    495
    PeterMcC
    Apr 23, 2006
  2. Martin Raychev
    Replies:
    1
    Views:
    280
    Alvin Bruney [MVP]
    Mar 2, 2004
  3. Z Yao

    Virus Concerns for Uploading Pictures

    Z Yao, Dec 29, 2005, in forum: ASP .Net Security
    Replies:
    0
    Views:
    107
    Z Yao
    Dec 29, 2005
  4. xool

    Uploading Pictures

    xool, Sep 23, 2003, in forum: ASP General
    Replies:
    5
    Views:
    96
    Antonin Foller
    Sep 23, 2003
  5. Ellie

    Uploading pictures to server

    Ellie, Aug 29, 2008, in forum: ASP General
    Replies:
    2
    Views:
    96
    Ellie
    Aug 29, 2008
Loading...

Share This Page