首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

ASP.NET中怎么实现上传 和下载图片功能

2012-01-19 
ASP.NET中如何实现上传 和下载图片功能ASP.NET中如何实现上传和下载图片功能[解决办法]using Systemusing

ASP.NET中如何实现上传 和下载图片功能
ASP.NET中如何实现上传   和下载图片功能

[解决办法]
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OracleClient;

public partial class _Default : System.Web.UI.Page
{
SqlDataAccess sda = new SqlDataAccess();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string filepath = FileUpload1.PostedFile.FileName;
string filename = filepath.Substring(filepath.LastIndexOf( "\\ ")+1);
string fileEx = filepath.Substring(filepath.LastIndexOf( ". ")+1);
string serverpath = "C:/aa/upload/ " + filename;
string dbpath = "\\upload\\ " + filename;
if (fileEx == "jpg " || fileEx == "bmp " || fileEx == "gif ")
{
FileUpload1.PostedFile.SaveAs(serverpath);
Response.Write( "成功 ");
Image1.ImageUrl = @ "..\aa\upload\ " + filename;
}
else
{
Response.Write( "失敗 ");
}
string sql = "insert into gc_carno(id,carno,model,carphoto) values(100, ' "+TextBox1.Text+ " ', ' "+TextBox2.Text+ " ', ' "+dbpath+ " ') ";
OracleConnection conn = sda.getoracleconnection();
conn.Open();
OracleCommand cmd = new OracleCommand(sql,conn);

int i = cmd.ExecuteNonQuery();
if (i == 1)
{
Response.Write( " <script language= 'javascript '> alert( '添加成功 ') </script> ");
}
else
{
Response.Write( " <script language= 'javascript '> alert( '添加失敗 ') </script> ");
}

}}

热点排行