uplogoimage.aspx前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="uplogoimage.aspx.cs" Inherits="Default4" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>上传头像</title>
<script language="javascript" type="text/javascript" src="ajax/jquery.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpimage" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="上传" />
<asp:Image ID="Image1" runat="server" ImageUrl="~/Fileupimage/b3.jpg" Visible="False" /></div>
</form>
</body>
</html>
uplogoimage.aspx后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 周昕 2009-6-8 上传头像
/// </summary>
protected void Button1_Click(object sender, EventArgs e)
{
//判断上传控件中是否有值
if (FileUpimage.HasFile == false)
{
//Response.Write("<script lanage='javascript'> alert('请指定上传的头像')</script>");
string clientScript = "var falseimage=parent.document.getElementById('falseimage');$(falseimage).html('请指定上传的头像');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "falseimage", clientScript, true);
}
else
{
string fType = FileUpimage.PostedFile.ContentType;//获取图像的类型
if (fType == "image/bmp" || fType == "image/gif" || fType == "image/pjpeg" || fType == "image/jpeg" || fType == "image/x-png")
{
//获取文件信息
FileInfo file = new FileInfo(FileUpimage.PostedFile.FileName);
///随机数据
Guid guid = Guid.NewGuid();
string stamp = guid.ToString("N");
//生成随机数
Random aa=new Random();
string number=aa.Next(10000).ToString();
//原始图片保存路径
string path = "~/Fileupimage/" + stamp + ".gif";
//缩略图保存路径
string spath = "~/Fileupimage/" + number + ".gif";
try
{
//原始图片保存
FileUpimage.SaveAs(Server.MapPath(path));
//缩略图保存
MakeThumbImage(Server.MapPath(path), Server.MapPath(spath), 200, 100);
//给隐藏的图片控件赋值并显示
//Image1.Visible = true;
//Image1.ImageUrl = spath;
string clientScript = "var userInfo1=parent.document.getElementById('userInfo');$(userInfo1).attr('src','Fileupimage/" + number + ".gif" + "');$(userInfo1).show();";
clientScript+="var falseimage=parent.document.getElementById('falseimage');$(falseimage).html('上传成功');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "successimage", clientScript, true);
//Response.Write("<script lanage='javascript'> alert('上传成功')</script>");
}
catch
{
//Response.Write("<script lanage='javascript'> alert('上传失败')</script>");
string clientScript = "var falseimage=parent.document.getElementById('falseimage');$(falseimage).html('上传失败');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "falseimage", clientScript, true);
}
}
else
{
//Response.Write("<script lanage='javascript'> alert('上传头像格式不正确')</script>");
string clientScript = "var falseimage=parent.document.getElementById('falseimage');$(falseimage).html('上传头像格式不正确');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "falseimage", clientScript, true);
}
}
}
///<summary>
///创建日期:2009-6-08
///创建人 :周昕
///方法名称:MakeThumbImage
///内容摘要:生成缩略图
/// </summary>
/// <param name="sPath">源图路径(物理路径)</param>
/// <param name="stPath">缩略图路径(物理路径)</param>
/// <param name="nWidth">缩略图宽度</param>
/// <param name="nHeight">缩略图高度</param>
private void MakeThumbImage(string sPath, string stPath, int nWidth, int nHeight)
{
System.Drawing.Image sImage = System.Drawing.Image.FromFile(sPath);
int tw = nWidth;
int th = nHeight;
///原始图片的宽度和高度
int sw = sImage.Width;
int sh = sImage.Height;
if (sw > tw)
{
sw = tw;
}
if (sh > th)
{
sh = th;
}
System.Drawing.Bitmap objPic, objNewPic;
objPic = new System.Drawing.Bitmap(sPath);
objNewPic = new System.Drawing.Bitmap(objPic, sw, sh);
objNewPic.Save(stPath);
sImage.Dispose();
objPic.Dispose();
objNewPic.Dispose();
}
}
upImage.aspx前台代码:调用uplogoimage.aspx页面进行上传。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="upImage.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>上传头像</title>
<script language="javascript" type="text/javascript" src="ajax/jquery.js"></script>
<script language="javascript" type="text/javascript">
$("document").ready(function(){$("#userInfo").hide()});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td style="height: 260px">
<iframe id="uploadLogo" frameborder="0" scrolling="no" src="uplogoimage.aspx" style="width: 300px; height: 100px; margin-top:10px"></iframe></td>
<td style="height: 260px; width: 236px;"><img src="" id="userInfo" /><span id='falseimage'></span> </td></tr> </table>
</div>
</form>
</body>
</html>
upImage.aspx后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
分享到:
相关推荐
spring.net案例原码 spring.net案例原码 spring.net案例原码 spring.net案例原码
### ASP.NET 文件上传与下载实现方法 #### 一、引言 在Web应用程序开发中,文件上传和下载是一项常见的功能需求。ASP.NET提供了一系列强大的工具和技术来帮助开发者轻松实现这一功能。本文将详细介绍如何利用ASP...
ASP.NET框架原码分析 在IT领域,ASP.NET框架是一个由微软公司开发的开源Web应用程序框架,用于构建高效、可维护的动态网站。这个框架基于.NET Framework,为开发者提供了丰富的功能和工具,使得构建Web应用变得更加...
ASP.NET 是微软公司开发的一种用于构建Web应用程序的框架,它基于.NET Framework,为开发者提供了丰富的功能和工具,简化了Web应用的开发过程。这个实例源码可能是为了展示如何使用ASP.NET来开发一个在线考试系统,...
ASP.NET企业网站原码是一个基于微软的ASP.NET技术构建的网站应用模板,它为企业级网站开发提供了一套完整的解决方案。ASP.NET是微软.NET框架的一部分,主要用于构建动态网页和Web应用程序。这个原码不仅可以用于快速...
ASP.NET天气预报原码是一个基于ASP.NET技术实现的项目,旨在提供国内所有城市的实时天气预报信息。这个项目的核心功能是获取并展示中国各地的气象数据,帮助用户了解最新的天气状况,以便于规划日常生活或工作。下面...
综上所述,.NET调用PHP原码涉及到的技术点包括Web服务、COM组件、编译器(Phalanger)、第三方库、HTTP客户端类以及异步编程。选择合适的方法取决于具体需求,例如系统的兼容性、性能要求、安全性等因素。通过这些...
本项目名为"asp.net门户网原码",表明这是一个使用ASP.NET技术构建的企业级门户网站的完整源代码。以下将详细介绍该原码中可能包含的关键知识点和技术。 1. **MVC架构**:ASP.NET MVC(Model-View-Controller)是...
本文将深入探讨Silverlight 4.0中实现图片上传到Web服务器的相关知识点,以及如何通过原码理解这一过程。 1. **Silverlight 4.0概述** Silverlight 4.0是该技术的一个重要版本,它提供了许多增强功能,包括对桌面...
在ASP.NET中,这通常通过控件如`ImageControl`或`LiteralControl`实现,并在服务器端生成图表的图片。 ```csharp using (System.IO.MemoryStream stream = new MemoryStream()) { chart.SaveImage(stream, ...
《基于VB.NET的条形码生成软件开发详解》 在信息技术高速发展的今天,条形码作为数据快速输入和交换的重要工具,在各行各业得到了广泛的应用。本文将深入探讨如何使用VB.NET编程语言开发一款条形码生成软件,从源...
本文将基于"Insus.NET:七道最经典的asp.net页面传值题答案(附原码)"这一主题,深入探讨七种常见的页面传值方法,并通过实际的代码示例来帮助你理解每种方法的用法。 1. QueryString参数传递: 这是最直观的方式,...
《.NET ASP.NET 办公自动化系统OA源码解析与应用》 在信息化时代,办公自动化(Office Automation,简称OA)系统已经成为企业管理和运营的重要工具。.NET ASP.NET技术是微软公司推出的一种强大的Web应用程序开发...
【描述】中提到的“点滴记忆i520,美好的生活需要用心记录”,意味着该源码可能包含了一种简洁、易用的用户界面,让用户能够轻松上传个人生活中的照片,保存和分享美好瞬间。"极致上传"暗示了它在上传速度和用户体验...
ASP.NET视频点播系统是一种基于微软的ASP.NET技术构建的在线多媒体服务平台,它允许用户浏览、选择并在线播放各种视频内容。在这个毕业设计项目中,开发者利用ASP.NET的强大功能,构建了一个用户友好的界面和高效的...
Verilog原码二位乘法器,其中两个操作数位宽为5。文件中含解释文档,代码中含tb文件和详细注释。配合https://blog.csdn.net/qq_42334072/article/details/105928385食用更佳
【ASP.NET技术基础】 ASP.NET是由微软开发的一种服务器端Web应用程序框架,用于构建动态网站、Web应用程序和服务。它建立在.NET Framework之上,提供了一种高效、高性能的方式来开发和部署网络应用。ASP.NET提供了...
在这个场景中,我们讨论的是一个基于VB.NET开发的XML文件编辑器,该编辑器适用于.NET Framework 1.0环境,这意味着它是针对较早版本的.NET平台设计的,可能不包含后来版本中引入的新特性和优化。 XML文件编辑器的...