asp.net ajax and ASP.net 2.0 fileupload to create a no refresh file upload Control

Source: Internet
Author: User
Tags format object datetime file upload net string tostring
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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.