Re: FN-FORUM: .NET image upload component
date posted 10th October 2007 14:54
Craig wrote:
> Thanks Ben,
>
> I had a look at the namespaces you suggested however, I don't want to create
> a graphic, I just want to upload one and interrogate it's properties, like
> width and height. Microsoft's docs are unintelligible to me as I'm not
> already an expert, hence I was looking for a component I could install and
> call simply without spending days and days of frustration, which is usually
> the case with .NET.
>
I would suggest maybe subcontracting some stuff out to a programmer to
be honest. Much easier to do that than spend a lot of money on a
component to do a job which is handed to you on a plate by the platform
you're already paying for.
Here is a bit of sample C# code that I used for this job - works fine in
context but there may be a few variables from elsewhere in the class
that aren't in here so I doubt it would cut and paste into whatever you
have. It was attached to the "upload" button click event. This has a
wide selection of uploadable types rather than just images, but it
should be pretty clear what it's doing and as usual with C# it's trivial
to swap into VB.
===========================================================
HttpPostedFile newFile = myUploadBox.PostedFile;
if ((newFile != null) && (newFile.ContentLength > 0))
{
string ipath="/uploaded_images/";
int filetype_legitimate = -1;
string[] fileTypes = {".jpg", ".gif", ".png", ".doc",
".ppt", ".pdf", ".xls", ".csv", ".zip"};
string[] graphicFileTypes = {".jpg", ".gif", ".png"};
string ext = Path.GetExtension(newFile.FileName).ToLower();
fileExtension=ext;
for (int i=0;i100)
{
scalefactor = (xSize/100);
xSize=100;
ySize=(ySize/scalefactor);
}
}
else
{
if (ySize>100)
{
scalefactor = (ySize/100);
ySize=100;
xSize=(xSize/scalefactor);
}
}
System.Drawing.Image newSmall =
newBmp.GetThumbnailImage(xSize, ySize, null, new IntPtr());
newSmall.Save( Server.MapPath(ipath+smallFile));
thumb=String.Concat(ipath, smallFile);
ViewState[ThumbKey]=thumb;
Consequence.Text = "Image Uploaded";
=========================================================================
Hope that helps.
-ben