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 !




Simple code to save image in asp.net


Posted Date: 13 Sep 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: Vivek SharmaMember Level: Gold    
Rating: Points: 10



This is the simple code to save an image.Write this code on button click and make folder with name "images" in solution explorer. And "tb_description" is the name of table.


protected void btnSave_Click(object sender, EventArgs e)
{
cmd.CommandText = "insert into tb_description (image,description) values(@image,@description)";
cmd.Connection = con;
con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ToString();
con.Open();
cmd.Parameters.Add("@description", SqlDbType.NVarChar, 2000).Value = TextBox2.Text;
String Picture;
String fp1;
fp1 = FileUpload1.PostedFile.FileName;
if (fp1.ToString() != "")
{
String fn1;
fn1 = fp1.Substring(fp1.LastIndexOf("\\") + 1);
String sp1;
sp1 = Server.MapPath("images");
if (sp1.EndsWith("\\") == false)
{
sp1 += "\\";
}
sp1 += fn1;
FileUpload1.PostedFile.SaveAs(sp1);
Picture = fn1;
}
else
{
Picture = "Noimage.jpg";
}
cmd.Parameters.Add("@image", SqlDbType.NVarChar, 200).Value = Picture;
cmd.ExecuteNonQuery();
}






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Simple code to save image in asp.net  .  How to save image in asp.net  .  Code to save image in asp.net  .  Code to save image  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to get value from checkboxList using javascript in asp.net 2.0?
Previous Resource: How to enable Paging and sorting without coding in gridview
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use