.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

fileupload

Posted By: Shweta     Posted Date: May 10, 2011    Points:5   Category :ASP.Net
i want to preview the image on the image control after browsing it through file upload before uploading it..
how can i do it??

Responses
Author: Gowthammanju             
Posted Date: May 23, 2011     Points: 20   

Hello!

you can use the following code to upload and view the upload document

place a
1)file uploader
2)label
3)image

kindly look at these

try
{
string filepath = fileupload_img.PostedFile.FileName;
string filename = Path.GetFileName(filepath);
string ext = Path.GetExtension(filename);
string contenttype = string.Empty;
switch (ext)
{
case ".jpg":

contenttype = "image/jpg";

break;

case ".png":

contenttype = "image/png";

break;

case ".gif":

contenttype = "image/gif";

break;
case ".doc":

contenttype = "document/doc";

break;
....................................................
.......type wat files u want......................
.........................................


default:
contenttype = "";
break;
}
if (contenttype != string.Empty)
{
lbl_attachments.Text = fileupload_img.FileName;
fileupload_img.SaveAs(Server.MapPath("~/Tempfiles/" + lbl_attachments.Text));
Image1.ImageUrl="~/Tempfiles/" + lbl_attachments.Text;

}
else
{

lbl_attachments.Text = "post files only! ";

}
}
catch (Exception ex)
{ Response.Write(ex.Message); }


where

fileupload_img is file uploader name,
lbl_attachments is lable name.
image1 is the image name.

then run it u will find solution




Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Narayanan             
Posted Date: July 18, 2011     Points: 20   

Hi,
http://msdn.microsoft.com/en-us/library/system.windows.controls.image.aspx
http://www.homeandlearn.co.uk/csharp/csharp_s4p8.html

Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend