哪有比较简单实用的图片上传程序!各位高手能推荐一下吗~!最好是ASP.NET 2.0(C#)的

解决方案 »

  1.   

    有个上传file的html控件的啊。
      

  2.   

    先用file控件,取得文件名和路径,
    然后File1.SaveAs("路径加文件名");
      

  3.   

    public void UpLoadPic()
            {
                if (inputFile.PostedFile.ContentLength > 0)
                {
                    if (IsValidFileType(inputFile.PostedFile.FileName))
                    {
                        System.Drawing.Image.GetThumbnailImageAbort backb = null;
                        //大图
                        string fullName = inputFile.PostedFile.FileName;
                        string newName = System.DateTime.Now.ToString("yyyyMMddhhmmss") + fullName.Substring(fullName.LastIndexOf("."));
                        string path = Server.MapPath("../PlayerPhotos");
                        inputFile.SaveAs(path + "/" + newName);
                                        }
                    else
                    {
                        Response.Write("<script>alert('出错了!上传文件格式不对!')</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('出错了!上传文件不能为空!')</script>");
                }
            }
            private bool IsValidFileType(string FileName)
            {
                string ext = FileName.Substring(FileName.LastIndexOf(".") + 1, FileName.Length - FileName.LastIndexOf(".") - 1);
                for (int i = 0; i < AcceptedFileTypes.Length; i++)
                {
                    if (ext.ToLower() == AcceptedFileTypes[i])
                    {
                        return true;
                    }
                }
                return false;
            }
      

  4.   

    private string[] AcceptedFileTypes = new string[] { "jpg", "jpeg", "jpe","gif"};
      

  5.   

    一个文件上传的类 
    http://teach.ehang.net/ArticleShow.aspx?key=352&classid=38
      

  6.   

    一个文件上传的类
    http://teach.ehang.net/ArticleShow.aspx?key=352&classid=38
      

  7.   

    我加了代码如下:
    UpLoadPic.aspx.csusing 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 UpLoadPic : System.Web.UI.Page
    {
        public void UpLoadPictrue()
        {
            if (inputFile.PostedFile.ContentLength > 0)
            {
                if (IsValidFileType(inputFile.PostedFile.FileName))
                {
                    System.Drawing.Image.GetThumbnailImageAbort backb = null;
                    //大图
                    string fullName = inputFile.PostedFile.FileName;
                    string newName = System.DateTime.Now.ToString("yyyyMMddhhmmss") + fullName.Substring(fullName.LastIndexOf("."));
                    string path = Server.MapPath("../PlayerPhotos");
                    inputFile.SaveAs(path + "/" + newName);
                }
                else
                {
                    Response.Write("<script>alert('出错了!上传文件格式不对!')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('出错了!上传文件不能为空!')</script>");
            }
        }
        private string[] AcceptedFileTypes = new string[] { "jpg", "jpeg", "jpe", "gif" };
        private bool IsValidFileType(string FileName)
        {
            string ext = FileName.Substring(FileName.LastIndexOf(".") + 1, FileName.Length - FileName.LastIndexOf(".") - 1);
            for (int i = 0; i < AcceptedFileTypes.Length; i++)
            {
                if (ext.ToLower() == AcceptedFileTypes[i])
                {
                    return true;
                }
            }
            return false;
        }}UPloadPic.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UpLoadPic.aspx.cs" Inherits="UpLoadPic" %><!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">
            <asp:FileUpload ID="inputFile" runat="server" /><div>
        
        </div>
            <asp:Button ID="Button1" runat="server" Text="上传"/>
        </form>
    </body>
    </html>
    怎么让他执行啊,是不是要在ASPX里加个Button,然后加个Onclick事情,代码如何写,请高手指点