图片上传代码示例

ZDNet软件频道 时间:2008-06-29 作者:tag | 中国IT实验室 我要评论()
本文关键词:上传 图片 xml 软件
图片上传代码示例
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
using KunslyNetDll.Common;
using HunMSM.include;

namespace HunMSM.photo
{
    
/// <summary>
    
/// 图片上传
    
/// </summary>

    public partial class _upphoto : System.Web.UI.Page
    
{
        
public string sPath = "";
        
public string extension;
        
public string path;
        
public string fileName;
        
public string smobile;
        
protected void Page_Load(object sender, System.EventArgs e)
        
{
            
// 在此处放置用户代码以初始化页面
            AddControl();
            
if (Session["UserMobile"== null)            
                Response.Write(
"<script language=javascript>alert('请先登录,才允许上传图片');history.back(-1)</script>");
            
else
                smobile 
= Session["UserMobile"].ToString().Trim();
            
if(!this.IsPostBack)
            
{
                DropDownPhotoType();
                DropDownPhotoColl();
            }

        }


        
void AddControl()    

        
Web 窗体设计器生成的代码

        
protected void Button1_Click(object sender, System.EventArgs e)
        
{
            
int ncount = GetRecordCount();
            
if (ncount == 0)
            
{
                KunslyWebPage.ShowMessage(
this,"请先创建相册,才允许上传图片");
                
return;
            }

            
//    Response.Write("<script language=javascript>alert('请先创建相册,才允许上传图片');history.back(-1)</script>");
            
//else
            
//{
            if(UploadFile.PostedFile.FileName.Trim() == ""
            

                
//Response.Write("<script language=javascript>alert('老大,没文件怎么传啊');history.back(-1)</script>");
                KunslyWebPage.ShowMessage(this,"请选择文件");
                
return;
            }
 
            
//    else
            
//    {
            if (txtMessage.Text.Trim() == "")
            
{
                KunslyWebPage.ShowMessage(
this,"请输入简介");
                
return;            
            }

                
//Response.Write("<script language=javascript>alert('老大,请输入简介');history.back(-1)</script>");
            extension = Path.GetExtension(UploadFile.PostedFile.FileName).ToUpper(); 
            
            
if (extension != ".JPG" && extension != ".GIF")
            
{
                KunslyWebPage.ShowMessage(
this,"非法文件,不允许上传,只允许上传.jpg或.gif文件");
                
return;            
            }

            
//Response.Write("<script language=javascript>alert('非法文件,不允许上传');history.back(-1)</script>");
            if (UploadFile.PostedFile.ContentLength >= 1000000//大于1M不允许上传
            {
                KunslyWebPage.ShowMessage(
this,"文件过大,不能上传,单个文件最大不超过1M");
                
return;            
            }

            fileName 
= DateTime.Now.ToString("yyyyMMddhhmmss"); 
            path 
= Server.MapPath(""+ "/upfile/" + fileName + extension; 
            updata();
        }
    
                
                    
            
        


        
void updata()


        
void DropDownPhotoType()

        
void DropDownPhotoColl()

        
int GetRecordCount() 



    }

}

上传

图片

xml

软件


百度大联盟认证黄金会员Copyright© 1997- CNET Networks 版权所有。 ZDNet 是CNET Networks公司注册服务商标。
中华人民共和国电信与信息服务业务经营许可证编号:京ICP证010391号 京ICP备09041801号-159
京公网安备:1101082134