A
Alan Silver
Hello,
I am writing a page that allows the user to upload two images to the
server. I have two HTMLInputFile controls on the page ...
<input id="smallimage" Type="File" Runat="Server">
<br><input id="largeimage" Type="File" Runat="Server">
and the code that handle the postback looks like this...
if ((smallimage.PostedFile != null) && (smallimage.PostedFile.ContentLength > 0)) {
try {
smallimage.PostedFile.SaveAs(imagePath + "small.jpg");
} catch (Exception ex) {
// display an error message
}
}
if ((largeimage.PostedFile != null) && (largeimage.PostedFile.ContentLength > 0)) {
try {
largeimage.PostedFile.SaveAs(imagePath + "large.jpg");
} catch (Exception ex) {
// display an error message
}
}
Now, if I choose just a small image, then it gets saved twice, once as
"small.jpg" and once as "large.jpg". If I choose both images, then the
small one gets saved twice (ie the large one is ignored). If I only
choose the large image, then it saves something that isn't an image.
Presumably this is the non-existent small image.
I'm sure I'm making some basic mistake here. Please could someone show
me how to handle two file controls on one page.
Thanks in advance.
I am writing a page that allows the user to upload two images to the
server. I have two HTMLInputFile controls on the page ...
<input id="smallimage" Type="File" Runat="Server">
<br><input id="largeimage" Type="File" Runat="Server">
and the code that handle the postback looks like this...
if ((smallimage.PostedFile != null) && (smallimage.PostedFile.ContentLength > 0)) {
try {
smallimage.PostedFile.SaveAs(imagePath + "small.jpg");
} catch (Exception ex) {
// display an error message
}
}
if ((largeimage.PostedFile != null) && (largeimage.PostedFile.ContentLength > 0)) {
try {
largeimage.PostedFile.SaveAs(imagePath + "large.jpg");
} catch (Exception ex) {
// display an error message
}
}
Now, if I choose just a small image, then it gets saved twice, once as
"small.jpg" and once as "large.jpg". If I choose both images, then the
small one gets saved twice (ie the large one is ignored). If I only
choose the large image, then it saves something that isn't an image.
Presumably this is the non-existent small image.
I'm sure I'm making some basic mistake here. Please could someone show
me how to handle two file controls on one page.
Thanks in advance.