日期:2014-05-18  浏览次数:20525 次

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> ");
}

}}