那位大哥有关于附件上传的代码? 那位大哥关于附件上传的资料有附件上传的代码或资料,谢了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://search.csdn.net/search.asp?key=.net%C9%CF%B4%AB%CE%C4%BC%FE&pre=.net+%C9%CF%B4%AB%CE%C4%BC%FE&option=nmlres&result=normal&page=1&size=10&x=37&y=10 保存path.PostedFile.SaveAs (Server.MapPath(路径)) ;(path是个 type= file的控件)其他的自己想把 string strPath="Annex";//附件路径string strPathValue;//保存到数据库的值strPath=strPath + "\\" + Path.GetFileName(AccessoryPath.PostedFile.FileName);//AccessoryPath为File控件(设成服务器端控件)AccessoryPath.PostedFile.SaveAs(Request.MapPath(strPath));strPathValue="./"+ strPath.Replace("\\","/");//将存入数据库或提取出来...... hif.PostedFile.SaveAs(FileName);//hif为HTML File控件Runat="Server" C#语言<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %><%@ import Namespace="System" %> <%@ import Namespace="System.IO" %> <%@ import Namespace="System.Drawing" %> <%@ import Namespace="System.Drawing.Imaging" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><script language="c#" runat="server">protected void Page_Load(Object Src, EventArgs E){ if (!IsPostBack){ DataBind(); }}void GetThumbnailImage(String OldFile,String NewFile){ Double OWidth,OHeight,NWidth,NHeight; int Width,Height; System.Drawing.Image OldImage = System.Drawing.Image.FromFile(OldFile); OWidth=OldImage.Width; OHeight=OldImage.Height; if(OWidth>OHeight){//横图 NWidth=250; NHeight=NWidth*OHeight/OWidth; }else{//竖图 NHeight=250; NWidth=NHeight*OWidth/OHeight; } Width=Convert.ToInt32(NWidth); Height=Convert.ToInt32(NHeight); System.Drawing.Image thumbnailImage = OldImage.GetThumbnailImage(Width,Height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); thumbnailImage.Save(NewFile); OldImage.Dispose();} bool ThumbnailCallback() { return true; } public void DoUpFile(Object src,EventArgs e){ int FileCount=Request.Files.Count; String UpLoadFileName; String UpLoadFileSize; String SaveFileName; String[] AFileName; int iFileSize; char[] de={'\\'}; System.Drawing.Image Image,ANewImage; int OWidth,OHeight,NWidth,NHeight; for(int i=0;i<FileCount;i++){ HttpPostedFile hpf=Request.Files[i]; AFileName=hpf.FileName.Split(de); UpLoadFileName=AFileName[AFileName.Length-1]; if (UpLoadFileName.Trim()!="" || UpLoadFileName.Trim()!=String.Empty){ SaveFileName=Server.MapPath("/")+"Other\\Feier\\"+UpLoadFileName; hpf.SaveAs(SaveFileName); GetThumbnailImage(SaveFileName,Server.MapPath("/")+"Other\\Small\\"+UpLoadFileName); iFileSize=Convert.ToInt32(hpf.ContentLength.ToString(),10); if(iFileSize>=1024){//大于1k UpLoadFileSize=(iFileSize/1024).ToString()+"K"; }else{ UpLoadFileSize=iFileSize.ToString(); } AddUpInfo(UpLoadFileName,UpLoadFileSize); }//end if }//end for }public void AddUpInfo(String FileName,String FileSize){ Label Lab_Info=new Label(); Lab_Info.Text=FileName+"已经上传成功!大小:"+FileSize+"字节<br>"; Pan_UpInfo.Controls.Add(Lab_Info);}void OnCreateSmallJPG(Object s,EventArgs e){ String ImgDir,smlDir; FileInfo FI; DirectoryInfo DI; String FileName,FileExt,FilePic; ImgDir=Server.MapPath("/Other/Feier"); smlDir=Server.MapPath("/Other/Small"); DirectoryInfo dir=new DirectoryInfo(ImgDir); foreach(FileSystemInfo fsi in dir.GetFileSystemInfos()){ FileName=""; if(fsi is FileInfo){ //表示当前是FSI文件 FI=(FileInfo)fsi; FileName=FI.Name; FileExt=FI.Extension; GetThumbnailImage(Server.MapPath("/")+"Other\\Feier\\"+FileName, Server.MapPath("/")+"Other\\Small\\"+FileName); }//end if }//end for }public void GetImgList(){ String ImgDir,smlDir; FileInfo FI; DirectoryInfo DI; String FileName,FileExt,FilePic; long FileSize; DateTime FileDate; int ImgNumber; ImgNumber=0; ImgDir=Server.MapPath("/Other/Feier"); smlDir=Server.MapPath("/Other/Small"); DirectoryInfo dir=new DirectoryInfo(smlDir); Response.Write("<table><tr>"); foreach(FileSystemInfo fsi in dir.GetFileSystemInfos()){ FilePic=""; FileName=""; FileExt=""; FileSize=0; if(fsi is FileInfo){ //表示当前是FSI文件 FI=(FileInfo)fsi; FileName=FI.Name; FileExt=FI.Extension; FileSize=FI.Length; FileDate=FI.LastWriteTime; if(ImgNumber==3){//上一行已经三个图片了,换行 Response.Write("</tr><tr>"); ImgNumber=0; } Response.Write("<td><a href='/Other/Feier/"+FileName+"' target='_blank'><img src='/Other/Small/"+FileName+"' border='0'></a></td>"); ImgNumber=ImgNumber+1; }//end if }//end for Response.Write("</tr></table>");}</script><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>上传图片</title><style type="text/css"><!--body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px;}--></style></head><body><form enctype="multipart/form-data" runat="server"><center><table width="780" border="0"> <tr> <td>文件上传 </td> </tr> <tr> <td> <table width="100%" border="1"> <tr> <td >文件 1: <input name="textfield1" type="file" id="UpFile1" size="50" runat="server"></td> </tr> <tr> <td>文件 2: <input name="textfield2" type="file" id="UpFile2" size="50" runat="server"></td> </tr> <tr> <td>文件 3: <input name="textfield3" type="file" id="UpFile3" size="50" runat="server"></td> </tr> <tr> <td>文件 4: <input name="textfield4" type="file" id="UpFile4" size="50" runat="server"></td> </tr> <tr> <td>文件 5: <input name="textfield5" type="file" id="UpFile5" size="50" runat="server"></td> </tr><!-- <tr> <td>文件 6: <input name="textfield6" type="file" id="UpFile6" size="50" runat="server"></td> </tr> <tr> <td>文件 7: <input name="textfield7" type="file" id="UpFile7" size="50" runat="server"></td> </tr> <tr> <td>文件 8: <input name="textfield8" type="file" id="UpFile8" size="50" runat="server"></td> </tr> <tr> <td>文件 9: <input name="textfield" type="file" id="UpFile9" size="50" runat="server"></td> </tr> <tr> <td>文件10: <input name="textfield9" type="file" id="UpFile10" size="50" runat="server"></td> </tr>--> </table> <input name="Btn_Up" type="Submit" value="上传" onServerClick="DoUpFile" runat="server"> <asp:Button ID="Btn_Create" runat="server" Text="重建缩略图" OnClick="OnCreateSmallJPG" /> <asp:Panel id="Pan_UpInfo" runat="server" /> </td> </tr> <tr> <td><% GetImgList(); %></td> </tr></table></center></form></body></html> 怎么把上传的附件保存到Oracle的Blob字段中 火狐 不支持 按钮事件? 发送邮件中包含链接,点击一次后使其失效,不要用数据库 博客改网站 c# 从excel中导入数据库中字符串超过255个就被截断 上传文件类型判断的问题 存储过程形成报表问题 关于事务,vb.net语言 Repeater控件,我晕 初学用户控件ascx遇到的问题 嘿嘿,我散分,关于xml 一个项目有几百表,数据层是写一个类呢?还是按功能或其它方法写多个类好呢? 急~~新人300分求解一简单问题。决不食言。
path.PostedFile.SaveAs (Server.MapPath(路径)) ;(path是个 type= file的控件)其他的自己想把
string strPathValue;//保存到数据库的值
strPath=strPath + "\\" + Path.GetFileName(AccessoryPath.PostedFile.FileName);//AccessoryPath为File控件(设成服务器端控件)
AccessoryPath.PostedFile.SaveAs(Request.MapPath(strPath));
strPathValue="./"+ strPath.Replace("\\","/");//将存入数据库或提取出来
......
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script language="c#" runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
if (!IsPostBack){
DataBind();
}
}
void GetThumbnailImage(String OldFile,String NewFile){
Double OWidth,OHeight,NWidth,NHeight;
int Width,Height;
System.Drawing.Image OldImage = System.Drawing.Image.FromFile(OldFile);
OWidth=OldImage.Width;
OHeight=OldImage.Height;
if(OWidth>OHeight){//横图
NWidth=250;
NHeight=NWidth*OHeight/OWidth;
}else{//竖图
NHeight=250;
NWidth=NHeight*OWidth/OHeight;
}
Width=Convert.ToInt32(NWidth);
Height=Convert.ToInt32(NHeight);
System.Drawing.Image thumbnailImage = OldImage.GetThumbnailImage(Width,Height,
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
thumbnailImage.Save(NewFile);
OldImage.Dispose();
} bool ThumbnailCallback()
{
return true;
} public void DoUpFile(Object src,EventArgs e){
int FileCount=Request.Files.Count;
String UpLoadFileName;
String UpLoadFileSize;
String SaveFileName;
String[] AFileName;
int iFileSize;
char[] de={'\\'}; System.Drawing.Image Image,ANewImage;
int OWidth,OHeight,NWidth,NHeight;
for(int i=0;i<FileCount;i++){
HttpPostedFile hpf=Request.Files[i];
AFileName=hpf.FileName.Split(de);
UpLoadFileName=AFileName[AFileName.Length-1];
if (UpLoadFileName.Trim()!="" || UpLoadFileName.Trim()!=String.Empty){
SaveFileName=Server.MapPath("/")+"Other\\Feier\\"+UpLoadFileName;
hpf.SaveAs(SaveFileName);
GetThumbnailImage(SaveFileName,Server.MapPath("/")+"Other\\Small\\"+UpLoadFileName);
iFileSize=Convert.ToInt32(hpf.ContentLength.ToString(),10);
if(iFileSize>=1024){//大于1k
UpLoadFileSize=(iFileSize/1024).ToString()+"K";
}else{
UpLoadFileSize=iFileSize.ToString();
}
AddUpInfo(UpLoadFileName,UpLoadFileSize);
}//end if
}//end for
}
public void AddUpInfo(String FileName,String FileSize){
Label Lab_Info=new Label();
Lab_Info.Text=FileName+"已经上传成功!大小:"+FileSize+"字节<br>";
Pan_UpInfo.Controls.Add(Lab_Info);
}void OnCreateSmallJPG(Object s,EventArgs e){
String ImgDir,smlDir;
FileInfo FI;
DirectoryInfo DI;
String FileName,FileExt,FilePic;
ImgDir=Server.MapPath("/Other/Feier");
smlDir=Server.MapPath("/Other/Small");
DirectoryInfo dir=new DirectoryInfo(ImgDir);
foreach(FileSystemInfo fsi in dir.GetFileSystemInfos()){
FileName="";
if(fsi is FileInfo){
//表示当前是FSI文件
FI=(FileInfo)fsi;
FileName=FI.Name;
FileExt=FI.Extension;
GetThumbnailImage(Server.MapPath("/")+"Other\\Feier\\"+FileName,
Server.MapPath("/")+"Other\\Small\\"+FileName);
}//end if
}//end for
}
public void GetImgList(){
String ImgDir,smlDir;
FileInfo FI;
DirectoryInfo DI;
String FileName,FileExt,FilePic;
long FileSize;
DateTime FileDate;
int ImgNumber;
ImgNumber=0;
ImgDir=Server.MapPath("/Other/Feier");
smlDir=Server.MapPath("/Other/Small");
DirectoryInfo dir=new DirectoryInfo(smlDir);
Response.Write("<table><tr>");
foreach(FileSystemInfo fsi in dir.GetFileSystemInfos()){
FilePic="";
FileName="";
FileExt="";
FileSize=0;
if(fsi is FileInfo){
//表示当前是FSI文件
FI=(FileInfo)fsi;
FileName=FI.Name;
FileExt=FI.Extension;
FileSize=FI.Length;
FileDate=FI.LastWriteTime;
if(ImgNumber==3){//上一行已经三个图片了,换行
Response.Write("</tr><tr>");
ImgNumber=0;
}
Response.Write("<td><a href='/Other/Feier/"+FileName+"' target='_blank'><img src='/Other/Small/"+FileName+"' border='0'></a></td>");
ImgNumber=ImgNumber+1;
}//end if
}//end for
Response.Write("</tr></table>");
}
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>上传图片</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
</head>
<body>
<form enctype="multipart/form-data" runat="server">
<center>
<table width="780" border="0">
<tr>
<td>文件上传
</td>
</tr>
<tr>
<td>
<table width="100%" border="1">
<tr>
<td >文件 1:
<input name="textfield1" type="file" id="UpFile1" size="50" runat="server"></td>
</tr>
<tr>
<td>文件 2:
<input name="textfield2" type="file" id="UpFile2" size="50" runat="server"></td>
</tr>
<tr>
<td>文件 3:
<input name="textfield3" type="file" id="UpFile3" size="50" runat="server"></td>
</tr>
<tr>
<td>文件 4:
<input name="textfield4" type="file" id="UpFile4" size="50" runat="server"></td>
</tr>
<tr>
<td>文件 5:
<input name="textfield5" type="file" id="UpFile5" size="50" runat="server"></td>
</tr>
<!--
<tr>
<td>文件 6:
<input name="textfield6" type="file" id="UpFile6" size="50" runat="server"></td>
</tr>
<tr>
<td>文件 7:
<input name="textfield7" type="file" id="UpFile7" size="50" runat="server"></td>
</tr>
<tr>
<td>文件 8:
<input name="textfield8" type="file" id="UpFile8" size="50" runat="server"></td>
</tr>
<tr>
<td>文件 9:
<input name="textfield" type="file" id="UpFile9" size="50" runat="server"></td>
</tr>
<tr>
<td>文件10:
<input name="textfield9" type="file" id="UpFile10" size="50" runat="server"></td>
</tr>
-->
</table>
<input name="Btn_Up" type="Submit" value="上传" onServerClick="DoUpFile" runat="server">
<asp:Button ID="Btn_Create" runat="server" Text="重建缩略图" OnClick="OnCreateSmallJPG" />
<asp:Panel id="Pan_UpInfo" runat="server" />
</td>
</tr>
<tr>
<td><% GetImgList(); %></td>
</tr>
</table>
</center>
</form>
</body>
</html>