zoukankan      html  css  js  c++  java
  • ASP.NET 2.0 图片上传

    /*后台代码*/
    
    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.IO;
    public partial >{
     protected void Page_Load(object sender, EventArgs e)
     {
    
     }
     protected void Button1_Click(object sender, EventArgs e)
     {
     string UploadFileName, UploadFileLastName;
     UploadFile> UploadFileLast> Random rd = new Random();//产生随机数
     int valationNo = 10 + rd.Next(99);//产生随机数
     string suiji = valationNo.ToString();//产生随机数
     string UpLoadFileTime = DateTime.Now.ToString("yyyyMMddHHmmss") + suiji;//得到系统时间并加上随机数以便生成上传图片名称
     string NewUploadFile>
    
     string UserDirectory = "TestFile";//所要创建文件夹的名字,实际运用中可为用户注册ID
     string UserPath = Server.MapPath("UploadFiles").ToString() + "//" + UserDirectory + "//" + "ProductsImages";
     if (!Directory.Exists(UserPath)) //如果文件夹不存在则创建
     {
     Directory.CreateDirectory(UserPath);
     }
     FileUpload1.PostedFile.SaveAs(NewUploadPahtName);//用保存的方法将图片上载
     string sUser_ProductsImageUrl = "UploadFiles/" + UserDirectory + "/" + "ProductsImages/" + NewUploadFileName;//得到服务端图片的虚拟路径
     //Response.Write(sUser_ProductsImageUrl);
     }
    }

  • 相关阅读:
    【Linux】sed笔记
    【Linux】nl笔记
    【Kubernetes】架构全图
    【Linux】tar压缩解压缩笔记
    【Docker】初识与应用场景认知
    【Ubuntu】16.04网卡信息配置
    常用枚举类
    mysql生成主键
    eclipse下mybatis-generator-config插件
    tomcat下载镜像地址
  • 原文地址:https://www.cnblogs.com/sontin/p/1929826.html
Copyright © 2011-2022 走看看