Español
//前台代码<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
http://www.w3.org/1999/xhtml " >
//后台代码
usando el sistema; usando System.Data; usando System.Configuration; usando System.Web; utilizando System.Web.Security; utilizando System.Web.UI; usando System.Web.UI.WebControls; usando System.Web.UI.WebControls.WebParts; usando System.Web.UI.HtmlControls; usando System.IO;
prueba de clase parcial pública: System.Web.UI.Page { Page_Load vacío protegido (remitente del objeto, EventArgs e) {
} Botón vacío protegido1_Click (remitente del objeto, EventArgs e) { cadena UploadFileName, UploadFileLastName; UploadFileName = FileUpload1.PostedFile.FileName;//文件在本地的原始位置UploadFileLastName = UploadFileName.Substring(UploadFileName.LastIndexOf(".") + 1);//得到文件的扩展名Aleatorio rd = nuevo Aleatorio();//产生随机数int valationNo = 10 + rd.Next(99);//产生随机数string suiji = valationNo.ToString();//产生随机数string UpLoadFileTime = DateTime.Now.ToString("yyyyMMddHHmmss") + suiji;//得到系统时间并加上随机数以便生成上传图片名称cadena NewUploadFileName = UpLoadFileTime + "." + UploadFileLastName;//产生上传图片的名称
string UserDirectory = "TestFile";//所要创建文件夹的名字,实际运用中可为用户注册ID string UserPath = Server.MapPath("UploadFiles").ToString() + "\" + UserDirectory + "\" + "ProductsImages"; if (!Directory.Exists(UserPath)) //如果文件夹不存在则创建{ Directorio.CrearDirectorio(RutaUsuario); } FileUpload1.PostedFile.SaveAs(NewUploadPahtName);//用保存的方法将图片上载string sUser_ProductsImageUrl = "UploadFiles/" + UserDirectory + "/" + "ProductsImages/" + NewUploadFileName;//得到服务端图片的虚拟路径//Response.Write(sUser_ProductsImageUrl); } } http://www.cnblogs.com/zm235/archive/2006/09/23/512673.html