Pages

Saturday 2 July 2011

Saving images to our application.

0 comments
 
Hi Friends,in this post i would like to explain how to save images from our PC to application.

* For this i took one FileUpLoad control, Button control and a Label control for displaying message.

Add the following name space:
using System.IO;

Code for button click event():

protected void Button1_Click(object sender, EventArgs e)
{
try
{
string filePath = FileUpload1.PostedFile.FileName;


string filename = Path.GetFileName(filePath);

FileUpload1.PostedFile.SaveAs(@"F:\\Asp.Net\FileUpload\Images\" + filename);

Label1.Text = "Image uploaded successfully.";
}
catch
{
Label1.Text = "Failed to upload image.";
}
}


Note:
F:\\Asp.Net\FileUpload is the application path.
Created Images folder in my application and saving uploaded images into Images folder.

Thank you...

Shout it

Leave a Reply