C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to get the image....


Posted Date: 04 Aug 2008      Total Responses: 2

Posted By: sathish       Member Level: Silver     Points: 1



HI Guys
I am trying to insert a default image into the database if the user does not pick any image in the Fileupload.I am trying to use the following code to upload the default image ..but I am not getting ..Please see the code and tell how to read the image...

UriBuilder uBuilder = new UriBuilder();
uBuilder.Scheme = HttpContext.Current.Request.Url.Scheme;
uBuilder.Host = HttpContext.Current.Request.Url.Host;
if (HttpContext.Current.Request.Url.Port != null)
uBuilder.Port = HttpContext.Current.Request.Url.Port;
uBuilder.Path = HttpContext.Current.Request.ApplicationPath;
String buildUrl = uBuilder.ToString();
buildUrl = buildUrl + "/web/images/ina.jpg";//localhost image
System.IO.Stream iStream = new System.Net.WebClient().OpenRead(buildUrl);
What can I do after this.....
This is the code for If user pick the image through FileUpload
System.IO.Stream inputStream = PhotoUpload.PostedFile.InputStream;
int imageLength = PhotoUpload.PostedFile.ContentLength;
byte[] imageBinary = new byte[imageLength];
int inputRead = inputStream.Read(imageBinary, 0, imageLength);
byte[] imageData = imageBinary;

Thanks&Regards
Arun






Responses

Author: http://ravipulluri.blogspot.com    04 Aug 2008Member Level: GoldRating:     Points: 2

you can check whether fileupload control is empty or not.
by this you can insert default images if he doesnt selects the image.



Author: Ramola    05 Aug 2008Member Level: SilverRating:     Points: 3

Hi Arun,
You can check with this if loop

if(uBuilder.PostedFile !=null && uBuilder.PostedFile.FileName!="")
{
/* Get the default image here*/
}



Post Reply
You must Sign In to post a response.
Next : how to get linklabel value in gridview
Previous : Calling Windows Service from ASP.NET Web App
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use