Topbar
Topbar
Sign in
|
Join
|
Client Center
Home
Products
Client Center
Contact
Purchase
Support forums
»
Products
»
Ajax Uploader
»
Re: Dimensions of uploaded image files
Re: Dimensions of uploaded image files
09-02-2009, 8:39 PM
cutechat
Joined on 07-22-2004
Posts 2,332
Re: Dimensions of uploaded image files
Reply
Quote
JG,
Please check this code :
<
%@ Page
Language
=
"C#"
Title
=
"First sample"
%
>
<
%@ Import
Namespace
=
"CuteWebUI"
%
>
<
%@ Register
TagPrefix
=
"CuteWebUI"
Namespace
=
"CuteWebUI"
Assembly
=
"CuteWebUI.AjaxUploader"
%
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"
>
<
script
runat
=
"server"
>
void InsertMsg(string msg)
{
ListBoxEvents.Items.Insert(0, msg);
ListBoxEvents.SelectedIndex
=
0
;
}
protected void UploadAttachments1_FileUploaded(object sender, UploaderEventArgs args)
{
//must copy the stream to MemoryStream, otherwise the stream may be locked by Image object
byte[]
data
=
new
byte[args.FileSize];
using (Stream
stream
=
args
.OpenStream())
{
stream.Read(data, 0, args.FileSize);
}
System.Drawing.Image
img
=
null
;
try
{
img
=
System
.Drawing.Image.FromStream(new MemoryStream(data));
}
catch
{
}
if (
img
== null)
{
InsertMsg("What you uploaded is not a image");
}
else
{
InsertMsg("You have uploaded a image : " + img.Width + "x" + img.Height);
}
}
</
script
>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
id
=
"Head1"
runat
=
"server"
>
</
head
>
<
body
>
<
form
id
=
"Form1"
runat
=
"server"
>
<
CuteWebUI:UploadAttachments
runat
=
"server"
ID
=
"UploadAttachments1"
OnFileUploaded
=
"UploadAttachments1_FileUploaded"
>
</
CuteWebUI:UploadAttachments
>
<
br
/>
<
div
>
Server Trace:
<
br
/>
<
asp:ListBox
runat
=
"server"
ID
=
"ListBoxEvents"
Width
=
"800"
>
</
asp:ListBox
>
</
div
>
</
form
>
</
body
>
</
html
>
Regards,
Terry
View Complete Thread