All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
一个表,有金额,有日期,如何按月统计金额_[SQL Server教程]
Asp.Net,通用数据操作类,(附通用数据基类)_[Asp.Net教程]
动态SQL四种类型的语句格式_mssql学习_编程技术
全面理解javascript的caller,callee,call,apply概念_JavaScript技术_编程技术
delphi删除数据表中的记录
asp.net2.0中使用session进行用户登录验证
VS2005下水晶报表如何实现动态数据源绑定-_[Asp.Net教程]
服务器响应HTTP的类型ContentType大全_JavaScript技术_编程技术
Asp.net生成htm静态文件的两种途径_.net资料_编程技术
Visual,C#,2.0泛型编程基础_[Asp.Net教程]
Reading number is top 10 pictures
A man's favorite things3--ZhouWeiTong
Soong ching ling's former residence1
From China fortress sora aoi3
The hot big eye big breast beauty3
Ashlynn Brooke a group sexy photo2
Absolutely shocked. National geographic 50 animal photographys7
Sora aoi possession of boudoir2
陪睡门马睿菈自曝写真 称首拍大尺度照片1
yy365网站上的美女2
这才是真正的人体艺术1
Download software ranking
Boxer's Top ten classic battle4
Unix video tutorial5
网络管理员第三版
Eclipse 4.2.2 For Win32
圣殿祭司的ASP.NET.2.0.开发详解-使用C#
Kung.Fu.Panda.2
Ashlynn Video4
Unix video tutorial15
apache-tomcat-6.0.33
Unix video tutorial4
aaa published in(发表于) 2013/12/15 8:41:45 Edit(编辑)
ASP.NET之上传文件管理策略_.net资料_编程技术

ASP.NET之上传文件管理策略_.net资料_编程技术

ASP.NET之上传文件管理策略_.net资料_编程技术-你的首页-uuhomepage.com







最近做的项目跟ASP.NET上传文件内容有关,故将代码贴出,以便网友查阅,提供解决此类问题思路:如出现任何不理解问题,请留言,及时帮您解决!









<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml" >

::::上传管理系统::::








Text="上传管理">




&nbsp;





原文件名:

上传到服务器:

缩略图地址:

文件类型:

文件大小:

文件拓展名:

上传日期:


图片预览:








&nbsp;







********************************************************




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 MWO.Model.Info;
using MWO.DAL.Info;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void ButtonUp_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile.FileName != null)
{
try
{
FileName.InnerHtml = FileUpload1.PostedFile.FileName;//GetPhotoName
UpDateTime.InnerHtml = DateTime.Now.ToShortDateString();//UpDateTime




#region SetPhotoSize
FileLength.InnerHtml = CountSize(FileUpload1.PostedFile.ContentLength);
if (FileUpload1.PostedFile.ContentLength > 1024 * 1024 * 2)
{
Response.Write("");
}
else
{
#region SetPhotoFormat
FileType.InnerHtml = FileUpload1.PostedFile.ContentType;
FileExtention.InnerHtml = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToUpper();
string m_FileName = "www.webjx.Com-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ffff").Replace(".", "-") + FileExtention.InnerHtml;
string m_sFileName = "www.webjx.Com-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ffff").Replace(".", "-") + FileExtention.InnerHtml;
if (FileExtention.InnerHtml == ".JPG")
{
string m_SavePath = Server.MapPath("./photo/") + m_FileName;
SaveDir.InnerHtml = m_SavePath;




#region SetSmallPhoto
this.MakeSmallImg(FileUpload1.PostedFile, this.Server.MapPath("./SPhoto/") + m_sFileName, 118, 90);
string m_sSavePath = this.Server.MapPath("./SPhoto/") + m_sFileName;
sSaveDir.InnerHtml = m_sSavePath;
#endregion




FileUpload1.PostedFile.SaveAs(m_SavePath);
Response.Write("");




#region SaveDataBasee
PhotoInfo m_PInfo = new PhotoInfo();
m_PInfo.Organization = "5173";
m_PInfo.PicName = FileName.InnerHtml;
m_PInfo.ServerName = "GLSDB";
m_PInfo.Cdate = DateTime.Now;
m_PInfo.Exp = FileExtention.InnerHtml;
m_PInfo.Flag = 0;
m_PInfo.GameNickName = "Bruce";//TextBox控件内容
m_PInfo.MoonStar = 0;
m_PInfo.ShowIndex = 0;
m_PInfo.SPicHttpAddr = m_sSavePath;
m_PInfo.Type = 0;
m_PInfo.Vote = 0;
m_PInfo.PicHttpAddr=m_SavePath;




PhotoDAO m_PDao = new PhotoDAO();
m_PDao.Insert(m_PInfo);
#endregion
}
else
{
Response.Write("");
}
#endregion
}
#endregion
}
catch (Exception m_Ex)
{
Response .Write ("");
}
}
else if (FileUpload1.PostedFile.FileName == "")
{
Response.Write("");
}
}




#region
///


/// 计算文件大小函数,Size为字节大小
///

/// 初始文件大小
///
public string CountSize(long Size)
{
string m_strSize = "";
long FactSize = 0; FactSize = Size;
if (FactSize <= 1024)
m_strSize = FactSize.ToString() + "Byte";
if(FactSize>=1024&&FactSize<=1048576)
m_strSize=(FactSize/1024).ToString ()+"K";
if (FactSize >= 1048576 && FactSize <= 10485760)
m_strSize = (FactSize / 1024 / 1024).ToString() + "M";
return m_strSize;
}
#endregion




#region SaveSmallPhoto
///


/// 高清晰缩略图算法
///

/// 图片文件对象
/// 要保存为缩略图的源文件
/// 宽度
/// 高度
public void MakeSmallImg(System.Web.HttpPostedFile postFile, string saveImg, System.Double Width, System.Double Height)
{




//SourcePhotoName
string m_OriginalFilename = postFile.FileName;
string m_strGoodFile = saveImg;




//GetPhotoObject From SourceFile
System.Drawing.Image m_Image = System.Drawing.Image.FromStream(postFile.InputStream, true);




System.Double NewWidth, NewHeight;
if (m_Image.Width > m_Image.Height)
{
NewWidth = Width;
NewHeight = m_Image.Height * (NewWidth / m_Image.Width);
}
else
{
NewHeight = Height;
NewWidth = (NewHeight / m_Image.Height) * m_Image.Width;
}




if (NewWidth > Width)
{
NewWidth = Width;
}
if (NewHeight > Height)
{
NewHeight = Height;
}




//GetPhotoSize
System.Drawing.Size size =new System.Drawing.Size((int)NewWidth, (int)NewHeight);
//The New of Bimp Photo
System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width, size.Height);
// The New of Palette
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
// Set HightQuality Arithmetic For Graphics
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//ClearCanvas
g.Clear(System.Drawing.Color.White);
//在指定位置画图
g.DrawImage(m_Image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
new System.Drawing.Rectangle(0, 0, m_Image.Width, m_Image.Height),
System.Drawing.GraphicsUnit.Pixel);




//SavePhoto Of HightFocus
bitmap.Save(m_strGoodFile, System.Drawing.Imaging.ImageFormat.Jpeg);
//DisposeRes
g.Dispose();
m_Image.Dispose();
bitmap.Dispose();
}




#endregion
}






















添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.