aspnet之上传文件管理策略aspnet技巧Word文档格式.docx
- 文档编号:5745073
- 上传时间:2023-05-05
- 格式:DOCX
- 页数:7
- 大小:16.73KB
aspnet之上传文件管理策略aspnet技巧Word文档格式.docx
《aspnet之上传文件管理策略aspnet技巧Word文档格式.docx》由会员分享,可在线阅读,更多相关《aspnet之上传文件管理策略aspnet技巧Word文档格式.docx(7页珍藏版)》请在冰点文库上搜索。
/title>
/head>
body>
formid="
form1"
runat="
divstyle="
border-right:
#ffff00thindashed;
border-top:
margin-bottom:
4px;
margin-left:
55px;
border-left:
line-height:
normal;
margin-right:
padding-top:
1px;
border-bottom:
letter-spacing:
position:
static;
background-color:
silver;
text-align:
center"
br/>
asp:
LabelID="
LabelTitle"
Font-Bold="
True"
Font-Size="
XX-Large"
ForeColor="
Black"
Text="
上传管理"
/asp:
Label>
FileUploadID="
FileUpload1"
Width="
369px"
/>
&
nbsp;
ButtonID="
ButtonUp"
Height="
21px"
Text="
上传"
67px"
OnClick="
ButtonUp_Click"
/>
LabelTitle2"
Red"
*上传文件不能超过2M"
b>
原文件名:
/b>
spanid="
FileName"
上传到服务器:
spanid="
SaveDir"
缩略图地址:
sSaveDir"
runat="
文件类型:
FileType"
文件大小:
FileLength"
文件拓展名:
FileExtention"
上传日期:
UpDateTime"
图片预览:
ImageID="
Image1"
ImageUrl="
~/Login.aspx"
BorderColor="
#0000C0"
/div>
/form>
/body>
/html>
****************************************************
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingMWO.Model.Info;
usingMWO.DAL.Info;
publicpartialclassLogin:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
}
protectedvoidButtonUp_Click(objectsender,EventArgse)
if(FileUpload1.PostedFile.FileName!
=null)
try
FileName.InnerHtml=FileUpload1.PostedFile.FileName;
//GetPhotoName
UpDateTime.InnerHtml=DateTime.Now.ToShortDateString();
//UpDateTime
#regionSetPhotoSize
FileLength.InnerHtml=CountSize(FileUpload1.PostedFile.ContentLength);
if(FileUpload1.PostedFile.ContentLength>
1024*1024*2)
Response.Write("
script>
alert(图片不能超过规定大小!
);
/script>
"
else
#regionSetPhotoFormat
FileType.InnerHtml=FileUpload1.PostedFile.ContentType;
FileExtention.InnerHtml=System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToUpper();
stringm_FileName="
www.MWO.Com-"
+DateTime.Now.ToString("
yyyy-MM-dd-HH-mm-ss-ffff"
).Replace("
."
"
-"
)+FileExtention.InnerHtml;
stringm_sFileName="
if(FileExtention.InnerHtml=="
.JPG"
)
stringm_SavePath=Server.MapPath("
./photo/"
)+m_FileName;
SaveDir.InnerHtml=m_SavePath;
#regionSetSmallPhoto
this.MakeSmallImg(FileUpload1.PostedFile,this.Server.MapPath("
./SPhoto/"
)+m_sFileName,118,90);
stringm_sSavePath=this.Server.MapPath("
)+m_sFileName;
sSaveDir.InnerHtml=m_sSavePath;
#endregion
FileUpload1.PostedFile.SaveAs(m_SavePath);
alert(图片文件保存成功!
#regionSaveDataBasee
PhotoInfom_PInfo=newPhotoInfo();
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;
PhotoDAOm_PDao=newPhotoDAO();
m_PDao.Insert(m_PInfo);
alert(图片格式不正确,请选择图片文件!
#endregion
catch(Exceptionm_Ex)
Response.Write("
alert("
+m_Ex.ToString()+"
elseif(FileUpload1.PostedFile.FileName=="
alert(上传文件不能为空!
#region
///<
summary>
///计算文件大小函数,Size为字节大小
/summary>
paramname="
Size"
初始文件大小<
/param>
returns>
/returns>
publicstringCountSize(longSize)
stringm_strSize="
longFactSize=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"
returnm_strSize;
#regionSaveSmallPhoto
///高清晰缩略图算法
postFile"
图片文件对象<
saveImg"
要保存为缩略图的源文件<
Width"
宽度<
Height"
高度<
publicvoidMakeSmallImg(System.Web.HttpPostedFilepostFile,stringsaveImg,System.DoubleWidth,System.DoubleHeight)
//SourcePhotoName
stringm_OriginalFilename=postFile.FileName;
stringm_strGoodFile=saveImg;
//GetPhotoObjectFromSourceFile
System.Drawing.Imagem_Image=System.Drawing.Image.FromStream(postFile.InputStream,true);
System.DoubleNewWidth,NewHeight;
if(m_Image.Width>
m_Image.Height)
NewWidth=Width;
NewHeight=m_Image.Height*(NewWidth/m_Image.Width);
NewHeight=Height;
NewWidth=(NewHeight/m_Image.Height)*m_Image.Width;
if(NewWidth>
Width)
if(NewHeight>
Height)
//GetPhotoSize
System.Drawing.Sizesize=newSystem.Drawing.Size((int)NewWidth,(int)NewHeight);
//TheNewofBimpPhoto
System.Drawing.Imagebitmap=newSystem.Drawing.Bitmap(size.Width,size.Height);
//TheNewofPalette
System.Drawing.Graphicsg=System.Drawing.Graphics.FromImage(bitmap);
//SetHightQualityArithmeticForGraphics
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,newSystem.Drawing.Rectangle(0,0,bitmap.Width,bitmap.Height),
newSystem.Drawing.Rectangle(0,0,m_Image.Width,m_Image.Height),
System.Drawing.GraphicsUnit.Pixel);
//SavePhotoOfHightFocus
bitmap.Save(m_strGoodFile,System.Drawing.Imaging.ImageFormat.Jpeg);
//DisposeRes
g.Dispose();
m_Image.Dispose();
bitmap.Dispose();
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- aspnet 上传 文件 管理 策略 技巧
![提示](https://static.bingdoc.com/images/bang_tan.gif)