博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
how to enable fileupload and button control after once uploading of images
阅读量:5049 次
发布时间:2019-06-12

本文共 4159 字,大约阅读时间需要 13 分钟。

<% @PageLanguage="C#"AutoEventWireup="true"CodeFile="FileuploadandButton.aspx.cs"Inherits="DataControl_FileuploadandButton" %> 
< htmlxmlns="http://www.w3.org/1999/xhtml">< headid="Head1"runat="server">< title>
< scripttype="text/javascript"> $(document).ready(function () { InitializeImageSlider();}); function InitializeImageSlider() { $( '.flexslider').flexslider({ animation: "slide", controlNav: false, directionNav: false, itemWidth: "120%", itemHeight: "50px", slideshowSpeed: 2000, }); }
  #divMessage {   height: 205px;   width: 347px;   top: 29px;   left: 375px;   position: absolute; }  #form1 {   height: 783px; }   img{max-width:100%; height:400px; display: block;} .style1 {   left: 448px;   top: 23px; }
 
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class DataControl_FileuploadandButton : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        if(!IsPostBack)        {           LoadImage();        }    }        private void LoadImage()    {        try        {                       string imagePath = "~/BannerImage/";            string imageSource = SiteBaseUrl + "/BannerImage/";            string PhotoFilePath = Server.MapPath(imagePath);            string divSlider = @"
    "; string fileSlide = string.Empty; string fileName = string.Empty; DirectoryInfo di = new DirectoryInfo(PhotoFilePath); FileInfo[] rgFiles = di.GetFiles("*.*"); foreach (FileInfo fi in rgFiles) { fileSlide =@"
  • "; divSlider += fileSlide; } divImageSlider.InnerHtml = divSlider +"
"; } catch (Exception ex) { } } public static string SiteBaseUrl { get { string orginalUrl = HttpContext.Current.Request.Url.AbsoluteUri; if (HttpContext.Current.Request.Url.Query.Length > 0) orginalUrl = orginalUrl.Replace(HttpContext.Current.Request.Url.Query, string.Empty); return orginalUrl.Replace(HttpContext.Current.Request.Url.AbsolutePath, string.Empty) + (( HttpContext.Current.Request.ApplicationPath == "/" ?"" : HttpContext.Current.Request.ApplicationPath)) + '/'; } } public void UploadImage() { if (CheckValidImage(FileUpload2)) { FileUpload2.PostedFile.SaveAs(MapPath("~") + "/BannerImage/" + FileUpload2.FileName); ShowErrorMsg("success", "Image Uploaded Successfully"); LoadImage(); } } private bool CheckValidImage(FileUpload FileUploadImage) { string contentType; contentType = FileUploadImage.PostedFile.ContentType.ToLower(); if (contentType == "image/jpg" || contentType == "image/png" || contentType == "image/jpeg") { } else { ShowErrorMsg("error", "Image format is not valid. Valid image formats are ( jpg, png, jpeg)."); return false; } return true; } private void ShowErrorMsg(string _class, string _msg) { divMessage.Style.Value = "display:block;"; divMessage.Attributes.Add("class", _class); // divMessage.Attributes.Add("display", "block"); //divMessage.InnerHtml = _msg; Label test=new Label(); test.Text=_msg; divMessage.Controls.Add(test); } protected void btnsave_Click(object sender, EventArgs e) { } protected void btnUpload_Click(object sender, EventArgs e) { UploadImage(); }}

 FROM:

转载于:https://www.cnblogs.com/happy-Chen/p/3680052.html

你可能感兴趣的文章
【知识库】-数据库_MySQL 的七种 join
查看>>
.net 写文件上传下载webservice
查看>>
noSQL数据库相关软件介绍(大数据存储时候,必须使用)
查看>>
iOS开发——缩放图片
查看>>
HTTP之URL的快捷方式
查看>>
满世界都是图论
查看>>
配置链路聚合中极小错误——失之毫厘谬以千里
查看>>
Python codes
查看>>
【BZOJ4487】[JSOI2015] 染色问题(高维容斥)
查看>>
Ubuntu 环境变量
查看>>
一步一步学MySQL-日志文件
查看>>
bzoj3994: [SDOI2015]约数个数和
查看>>
hdu5306 Gorgeous Sequence
查看>>
Android中使用ListView实现下拉刷新和上拉加载功能
查看>>
proc文件系统的简介
查看>>
连续自然数和
查看>>
[SDOI2015]星际战争
查看>>
用好lua+unity,让性能飞起来——luajit集成篇/平台相关篇
查看>>
JS控制页面跳转
查看>>
递归与循环的区别
查看>>