uploading pictures

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

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?
 
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 withan
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
 
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
 
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
 
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....
 
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 belongingto
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
 
Back
Top