手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp.Net编程>列表

ASP.NET之上传文件管理策略

来源:互联网 作者:west263.com 时间:2008-02-22
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

FileUpload1.PostedFile.SaveAs(m_SavePath);
Response.Write("<script>alert('图片文件保存成功!');</script>");

#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("<script>alert('图片格式不正确,请选择图片文件!');</script>");
}
#endregion
}
#endregion
}
catch (Exception m_Ex)
{
Response .Write ("<script>alert('" m_Ex.ToString () "');</script>");
}
}
else if (FileUpload1.PostedFile.FileName == "")
{
Response.Write("<script>alert('上传文件不能为空!');</script>");
}
}

#region
/// <summary>
/// 计算文件大小函数,Size为字节大小
/// </summary>
/// <param name="Size">初始文件大小</param>
/// <returns></returns>
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
/// <summary>
/// 高清晰缩略图算法
/// </summary>
/// <param name="postFile">图片文件对象</param>
/// <param name="saveImg">要保存为缩略图的源文件</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
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);

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!