Freelancers Network
 
skill list top cap
Homepage
Join the Freelancer's Network
Update your details
Find a freelancer
Post a project
Find a project
Projects Archive
Post a job
Find a job
Jobs Archive
See Dan's Pages
See Andy's Pages
Link to this site
Resources
Join/Leave Forum
Forum Messages
+Additions+ Adverts
Advertising
Contact Us
Subscribe to our newsletter - enter your email address and hit return
Freelancers.net is owned and operated by Andy Stowell and Dan Winchester
skill list end cap
guru web hostcom

Find me again on Freelancers.net

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



Messages by Day
October 31st 2007
October 30th 2007
October 29th 2007
October 28th 2007
October 27th 2007
October 26th 2007
October 25th 2007
October 24th 2007
October 23rd 2007
October 22nd 2007
October 21st 2007
October 20th 2007
October 19th 2007
October 18th 2007
October 17th 2007
October 16th 2007
October 15th 2007
October 14th 2007
October 13th 2007
October 12th 2007
October 11th 2007
October 10th 2007
October 9th 2007
October 8th 2007
October 7th 2007
October 6th 2007
October 5th 2007
October 4th 2007
October 3rd 2007
October 2nd 2007
October 1st 2007


Messages by Month
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007


Messages by Year
2008
2007
2006
2005
2004
2003
2002
2001
2000