ajax|asp.net| Control | upload | upload Control | refresh | no refresh
In doing an information management platform to use the picture, like doing an uploaded
It's just asp.net ajax.
I tried to make a
No, it's fine.
Customizing user control Files Picupload.ascx
1<%@ control language= "C #" autoeventwireup= "true" inherits= "Admin_picupload, App_web_mboefw14"%>
2 <asp:image id= "Ep_image" runat= "Server" height= "160px" Imageurl= ' <%# Bind ("Ep_pic")%> '
3 width= "314px"/>
4<br/>
5<asp:fileupload id= "FileUpload1" runat= "Server"/>
6<asp:button id= "Button1" runat= "server" text= "upload"/>
Customizing user control Files PicUpload.ascx.cs
1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using system.web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12public Partial class Admin_PicUpload:System.Web.UI.UserControl
13{
protected void Page_Load (object sender, EventArgs e)
15 {
16
17}
protected void Button1_Click (object sender, EventArgs e)
19 {
BOOL FileOK = false;
21//Get root file absolute path
String path = Server.MapPath ("~/upload/");
23//If the file is uploaded, the file format is judged
FileUpload FU = FileUpload1;
if (FU. HasFile)
26 {
String fileextension = System.IO.Path.GetExtension (FU. FileName). ToLower ();
String[] allowedextensions ={". gif", ". jpg", ". png", ". bmp",};
for (int i = 0; i < allowedextensions.length; i++)
30 {
if (fileextension = = Allowedextensions[i])
32 {
FileOK = true;
34}
35}
36}
37//Call SaveAs method, implement upload file
if (FileOK)
39 {
Try
41 {
Fileupload1.saveas (path + System.DateTime.Now.ToString ("Yyyymmddhhmmss") +fu. FileName);
Ep_image.imageurl = ". /upload/"+ System.DateTime.Now.ToString (" Yyyymmddhhmmss ") + FU. FileName;
Button1.Text = "Upload success";
45}
Finally
47 {
48}
49}
Or else
51 {
Button1.Text = "Upload failed, format not allowed";
53}
54}
55}
56
Gradually complete ...
Http://www.cnblogs.com/zhiyyang/archive/2006/12/11/589020.html