
Simple one this (I hope) but can't figure it out.
I want to resize the uploaded image and overwrite the uploaded file (in the target folder) with the resized one.
Is there any code available on how to do this?
Andy
9 Answers, 1 is accepted

Try the following code snippet to resize uploaded images.
ASPX:
<
telerik:RadUpload
ID
=
"RadUpload1"
runat
=
"server"
></
telerik:RadUpload
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Button"
onclick
=
"Button1_Click"
/>
C#:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
foreach
(UploadedFile file
in
RadUpload1.UploadedFiles)
{
string
target = Server.MapPath(
"~/upload"
);
if
(!Directory.Exists(target))
{
Directory.CreateDirectory(target);
}
file.SaveAs(Path.Combine(target, file.GetName()));
using
(Bitmap originalImage =
new
Bitmap(file.InputStream))
{
int
width = newwidth;
int
height = (originalImage.Height * newwidth) / originalImage.Width;
Bitmap thumbnail =
new
Bitmap(width, height);
using
(Graphics g = Graphics.FromImage((System.Drawing.Image)thumbnail))
g.DrawImage(originalImage, 0, 0, width, height);
string
thumbnailFileName = Path.Combine(target,
string
.Format(
"{0}_bthumb{1}"
, file.GetNameWithoutExtension(), file.GetExtension()));
thumbnail.Save(thumbnailFileName);
}
}
}
Please take a look into this for more information.
Regards,
Shinu.

The file.saveas is failing. I had this with code I put together from the link you supplied.
Could not find file 'C:\InTouch\Activity App\into-activity-v6.2\Web\App_Data\RadUploadTemp\qryh2plj.ija'.
The file is in the folder following upload, but on click, it disappears, so by the time the file.saveas is fired the flie is gone.
Andy

Andy
Here is a sample web page where this functionality is implemented and is working properly. Please review it and let me know if you have further questions.
Plamen
the Telerik team

Its exacly the same, I have also tried removing the AJAX manager and the client side scripts.
Andy

<
telerik:RadAsyncUpload
ID
=
"ruKioskAreaImage"
runat
=
"server"
AutoAddFileInputs
=
"true"
MaxFileInputsCount
=
"1"
InitialFileInputsCount
=
"1"
MultipleFileSelection
=
"Disabled"
AllowedFileExtensions
=
"jpg,jpeg"
OnClientValidationFailed
=
"validationFailed"
OnClientFileUploadRemoved
=
"fileRemoved"
InputSize
=
"24"
ControlObjectsVisibility
=
"None"
OnFileSelected
=
"ruKioskAreaImage_FileSelected"
Width
=
"230px"
EnableEmbeddedSkins
=
"False"
Skin
=
"Activity"
>
</
telerik:RadAsyncUpload
>
function validationFailed(sender, eventArgs) {
$find(
"<%= AjaxManager.ClientID %>").ajaxRequest("SizeValidation");
}
function fileRemoved(sender, eventArgs) {
$find(
"<%= AjaxManager.ClientID %>").ajaxRequest("FileRemoved");
}

In the sample code, I had to remove the first file.SaveAs(Path.Combine(target, file.GetName())).
As this was causing the file to be moved.
thumbnail.Save(thumbnailFileName);
this is then used to same the file
Is this correct?
Andy
Unfortunately I could not quite understand what is was the code that worked for you from the explanation provided but if this is what you were finally trying to achieve I suppose it is correct.
Plamen
the Telerik team

hi,
sorry if I intrude in his speech, there is also a way to compress the image resized without losing quality? Perchp I noticed that the code you posted Andy works perfectly except that it has a large image 180x180 jpeg size on my hard = 5.80 kb once resized to 128x128 its size on disk is 16.1 kb, why?
hello