http://community.csdn.net/Expert/topic/5587/5587694.xml?temp=.7685358

解决方案 »

  1.   

    string filepath = FileUpload1.PostedFile.FileName;
            string filename = filepath.Substring(filepath.LastIndexOf("\\"));
            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>");
            }
      

  2.   

    做过java版本的,C#的还没有尝试过.
      

  3.   

    public void GenerateThumbNail(string sPhysicalPath,string sOrgFileName,
                                                                    string sThumbNailFileName,ImageFormat oFormat)
           {            try
                {
                     
                       System.Drawing.Image oImg = System.Drawing.Image.FromFile(sPhysicalPath + @"\" + sOrgFileName);                    System.Drawing.Image oThumbNail = new Bitmap(this.ThumbNailSize.Width, 
                                                                                                                     this.ThumbNailSize.Height, oImg.PixelFormat);                   Graphics oGraphic =  Graphics.FromImage(oThumbNail);                   oGraphic.CompositingQuality = CompositingQuality.HighQuality ;                   oGraphic.SmoothingMode = SmoothingMode.HighQuality ;                   oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic ;                   Rectangle oRectangle = new Rectangle(0, 0, this.ThumbNailSize.Width, this.ThumbNailSize.Height);                   oGraphic.DrawImage(oImg, oRectangle);
                  
                       oThumbNail.Save(sPhysicalPath + @"\" + sThumbNailFileName,oFormat); 
      
                       oImg.Dispose();             }
                catch (Exception)  { }       }
      

  4.   

    <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312"   validateRequest="false"%>
    <script language="C#" runat="server">
    public void DoUpLoad(Object sender,EventArgs e)
    {
      if(UploadFiles1.Value=="")
      {
    show.Text="Small pictrue Can't be empty!";
      }
      else
      {
        if(UploadFiles2.Value=="")
        {
    show.Text="Big pictrue Can't be empty!";
        }
    else
     {
            int FileCount=Request.Files.Count;
    string cun;
            for(int i=0;i<FileCount;i++)
            {
              HttpPostedFile hpf=Request.Files[i];
      if(hpf.ContentLength>200000)
              {
       show.Text="The files can't be more than 200KB!";
           break;
              }
          else
          {
          hpf.SaveAs(Server.MapPath("./uploadphoto/")+"\\"+DateTime.Now.ToString("yyyyMMddHHmms")+i+".jpg");
          cun="uploadphoto/"+DateTime.Now.ToString("yyyyMMddHHmms");
      showOK(cun);
              }
    }
     }
      }
    }
    public void showOK(string neirong)
    {
      tu_small.Text=neirong+"0.jpg";
      tu_big.Text=neirong+"1.jpg";
      showjg.Text="The pictures's way must not be modified,please do not renovate the web page!";
      show.Text="";
    }
    </script>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title></title>
    <link href="../images/new.css" rel="stylesheet" type="text/css">
    <style type="text/css">
    <!--
    body {
    background-color: #F5F5F5;
    }
    .style1 {color: #CC0000}
    -->
    </style>
    </head>
    <body>
    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="4%" height="44">&nbsp;</td>
        <td width="94%" valign="middle"><span class="style1">Add new product &nbsp;→</span></td>
        <td width="2%">&nbsp;</td>
      </tr>
      <tr>
        <td height="248">&nbsp;</td>
        <td valign="top" bordercolor="#55A0FF"> <table width="100%" border="0" cellspacing="1" cellpadding="0">
    <form runat="server">
          <tr>
            <td width="12%">Upload pictrue </td>
            <td width="88%" colspan="4"><table width="100%" height="41" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="13%" align="center">Small one </td>
                <td width="37%"><input type="file" id="UploadFiles1" runat="server"></td>
                <td width="7%" rowspan="2" align="center">
    <input type="submit" value="UpLoad" OnServerClick="DoUpLoad" runat="server" style="width:50; height:40; background-color: #000000;color:#ffffff;"></td>
                <td width="43%" rowspan="2">
    <asp:Label ID="show" runat="server" ForeColor="#009900"/> </td>
              </tr>
              <tr>
                <td align="center">Big one</td>
                <td><input type="file" id="UploadFiles2" runat="server"></td>
                </tr>
            </table></td>
            </tr>
          <tr>
            <td colspan="5">
    <table width="100%"  border="0" cellspacing="1" cellpadding="0">
                    <tr>
                      <td width="51%" height="24">
        &nbsp;Small one' way :&nbsp;                    <asp:Label ID="tu_small" runat="server"/><br>
                        &nbsp;Big one' way :&nbsp;                    <asp:Label ID="tu_big" runat="server"/>                    </td>
                      <td width="49%"><asp:Label ID="showjg" runat="server" ForeColor="#CC0000"/></td>
                    </tr>
                </table> </td>
            </tr>
          <tr valign="top">
            <td height="168" colspan="5"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="1" colspan="2" bgcolor="#000000"></td>
              </tr>
              <tr>
                <td width="67%" height="278" align="left" valign="middle"><br>
                    </td>
                <td width="33%" align="left" valign="top">&nbsp;

                </td>
              </tr>
            </table></td>
          </tr>
    </form>
        </table> </td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>
      

  5.   

    后台:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    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;public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void bt_upload_Click(object sender, EventArgs e)
        {
            try
            {
                if (FileUpload1.PostedFile.FileName == "")
                {
                    this.lb_info.Text = "请选择文件!";
                }
                else
                {
                    string filepath = FileUpload1.PostedFile.FileName;
                    string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);
                    string serverpath = Server.MapPath("images/") + filename; //这里设置文件的保存路径
                    FileUpload1.PostedFile.SaveAs(serverpath);
                    this.lb_info.Text = "上传成功!";
                }
            }
            catch (Exception ex)
            {
                this.lb_info.Text = "上传发生错误!原因是:" + ex.ToString();
            }
        }
    }前台:
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
         <table style="width: 343px">
                <tr>
                    <td style="width: 100px">
                        单文件上传</td>
                    <td style="width: 100px">
                    </td>
                </tr>
                <tr>
                    <td style="width: 100px">
                        <asp:FileUpload ID="FileUpload1" runat="server" Width="475px" />
                        </td>
                    <td style="width: 100px">
                        <asp:Button ID="bt_upload" runat="server" OnClick="bt_upload_Click" Text="上传" /></td>
                </tr>
                <tr>
                    <td style="width: 100px; height: 21px;">
                        <asp:Label ID="lb_info" runat="server" ForeColor="Red" Width="183px"></asp:Label></td>
                    <td style="width: 100px; height: 21px">
                    </td>
                </tr>
            </table>    </div>
        </form>
    </body>
    </html>
    还要多文件上传吗?我这有
      

  6.   

    xiandawang() :
    你的程序里public 后面的partial什么意思?
    好像不对吧?
    怎么出错?
      

  7.   

    Partial 关键字可用于下面的上下文中:Class 语句 Structure 语句 
    msdn有啊
      

  8.   

    哦,我用的是2003,好像不能用Partial关键字
      

  9.   

    你把public partial class _Default : System.Web.UI.Page这句去掉试试
    看2003行不
      

  10.   

    string serverpath = Server.MapPath("images/") + filename; //这里设置文件的保存路径
    这句是说要在项目里加个名为images的文件夹
      

  11.   

    public partial class _Default : System.Web.UI.Page只要在2005里新建个asp.net项目就自动生成的,不是我写的.2003是没有,我记得.
      

  12.   

    把class也去掉?
    那怎么行呢
    你把你的Msn给我,我晚上问你吧,这会要下班了
      

  13.   

    public partial class _Default : System.Web.UI.Page这个整句都去掉吧,我记得2003里没自动生成这句,这个2005自动生成的
      

  14.   

    请参考:http://www.xproer.com/bbs/revert.aspx?fid=5&tid=656