<%@Page language="C#" %>
<%@import namespace="System.IO"%>
<%@import namespace="System.Data"%><script language="C#" runat="server">
public void Button_Submit(Object o, EventArgs e)
{
HttpPostedFile upFile = up_file.PostedFile;
int iFileLength = upFile.ContentLength;
try
{
if(iFileLength == 0)
{
txtMess.Text = "请选择要上传的文件!";
}
else
{
Byte[] FileByteArray = new Byte[iFileLength];
FileInfo info = new FileInfo(upFile.PostedFile.FileName);
upFile.PostedFile.SaveAs(Server.MapPath("./upFiles/") + "\\" + info.Name);
txtDesc.Text = "";
txtMess.Text = "OK!你已经成功上传了类型的文件";
}
}
catch(Exception ex)
{
txtMess.Text = ex.Message.ToString();
}
}
</script><html>
<head>
<title>上传图片</title>
</head>
<body bgcolor="#FFFFFA">
<form enctype="multipart/form-data" runat="server" id="form1">
<table runat="server" width=700 align=left id="table1" cellpadding=0 cellspacing =0 border=0>
<tr>
<td>上传图片</td>
<td>
<input type="file" id="up_file" runat="server" style="width:320" accept="text/*" name="up_file">
</td>
</tr>
<tr>
<td>文件说明</td>
<td>
<asp:TextBox runat="server" width=230 id="txtDesc" maintanstate="false" />
</td>
</tr>
<tr>
<td>
<asp:label runat="server" id="txtMess" forecolor=red maintainstate="false" />
</td>
<td>
<asp:Button runat="server" width=230 onclick="Button_Submit" text="上传" />
</td>
</tr>
</table>
</form>
</body>
</html>
<%@import namespace="System.IO"%>
<%@import namespace="System.Data"%><script language="C#" runat="server">
public void Button_Submit(Object o, EventArgs e)
{
HttpPostedFile upFile = up_file.PostedFile;
int iFileLength = upFile.ContentLength;
try
{
if(iFileLength == 0)
{
txtMess.Text = "请选择要上传的文件!";
}
else
{
Byte[] FileByteArray = new Byte[iFileLength];
FileInfo info = new FileInfo(upFile.PostedFile.FileName);
upFile.PostedFile.SaveAs(Server.MapPath("./upFiles/") + "\\" + info.Name);
txtDesc.Text = "";
txtMess.Text = "OK!你已经成功上传了类型的文件";
}
}
catch(Exception ex)
{
txtMess.Text = ex.Message.ToString();
}
}
</script><html>
<head>
<title>上传图片</title>
</head>
<body bgcolor="#FFFFFA">
<form enctype="multipart/form-data" runat="server" id="form1">
<table runat="server" width=700 align=left id="table1" cellpadding=0 cellspacing =0 border=0>
<tr>
<td>上传图片</td>
<td>
<input type="file" id="up_file" runat="server" style="width:320" accept="text/*" name="up_file">
</td>
</tr>
<tr>
<td>文件说明</td>
<td>
<asp:TextBox runat="server" width=230 id="txtDesc" maintanstate="false" />
</td>
</tr>
<tr>
<td>
<asp:label runat="server" id="txtMess" forecolor=red maintainstate="false" />
</td>
<td>
<asp:Button runat="server" width=230 onclick="Button_Submit" text="上传" />
</td>
</tr>
</table>
</form>
</body>
</html>
解决方案 »
- ASP.NET中无法使用PostgreSQL?
- 关于C#枚举的用法
- 怎样把.net framework打包到程序中
- 是否System.Web.Mail不能发送邮件???????????
- 新任务消息提示框相关问题+++++升级散分+++++++
- 网站名称注册管理暂行办法实施细则>>有人注册过网站名称吗
- 还是TreeView中的CheckBox问题,很难办。问了一次没有解决,请各位高手多帮帮忙
- 怎样在ViewState中保存自定义类对象!!!
- web中很多事件都没有,怎样使用这些事件。或者有哪些资料可供学习。
- 碰到一个奇怪的问题!
- 请问javascript实现的功能能不能用C#后台代码代替?
- 简单问题:如何填充Dropdownlist??
System.Drawing.Image img = System.Drawing.Image.FromFile(strFileName);
img.GetThumbnailImage(img.Width /2, img.Height / 2, null, IntPtr.Zero);
MemoryStream stream = new MemoryStream();
img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ContentType = "imgae/jpeg";
byte[] bytes = new Byte[(int)stream.Length];
stream.Close();
Response.BinaryWrite(bytes);
Response.End();
http://forum.lostinet.com/Forum.Aspx
里发
:)
Datalist中只能是传个id给aspx, 图片是一个url
不是用一个变量就能显示出来
在aspx页面 用datalist显示图片缩略图?
显示图片用这个
<img src="showimg.aspx?id=<%# DataBinder.Eval(Container.DataItem, "imgid")%>">
showimg.aspx
-----------------------------
<%@Page language="C#"%>
<%@import namespace="System.Data"%>
<%@import namespace="System.Data.SqlClient"%>
<script language="C#" runat="server">
public void Page_Load(Object o, EventArgs e)
{
int ImgID = Convert.ToInt32(Request.Params["id"]);
string strFileName = "c:\\images\\11.jpg";//加一个算法,来通过id取得相应的文件名
System.Drawing.Image img = System.Drawing.Image.FromFile(strFileName);
img.GetThumbnailImage(img.Width /2, img.Height / 2, null, IntPtr.Zero);
MemoryStream stream = new MemoryStream();
img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ContentType = "imgae/jpeg";
byte[] bytes = new Byte[(int)stream.Length];
stream.Close();
Response.BinaryWrite(bytes);
Response.End();
}
</script>
是定义一个newimg, 用它来存放缩略图
System.Drawing.Imgae newimg = img.GetThumbnailImage(img.Width /2, img.Height / 2, null, IntPtr.Zero);
newimg.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
我在.net 中通过设定输出image控件的大小来达到缩略?不知可否?
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO ;
namespace Grgdt.Products
{
/// <summary>
/// ProductIndex 的摘要说明。
/// </summary>
public class ProductIndex : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgClass;
protected System.Web.UI.WebControls.TextBox txtKeys;
protected System.Web.UI.WebControls.Button btnSearch;
protected System.Web.UI.WebControls.DataList ProductList1;
protected System.Web.UI.WebControls.DataList ProductList2;
protected System.Web.UI.WebControls.DataList ProductList3;
protected System.Web.UI.WebControls.DataList DataList1;
protected System.Web.UI.WebControls.DataList ProductList4;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!Page.IsPostBack)
{
//string strFileName ="aa.jpg";
System.Drawing.Image img = System.Drawing.Image.FromFile("aa.jpg");
System.Drawing.Image newimg = img.GetThumbnailImage(img.Width /2, img.Height / 2, null, IntPtr.Zero); MemoryStream stream = new MemoryStream();
newimg.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ContentType = "imgae/jpeg";
byte[] bytes = new Byte[(int)stream.Length];
stream.Close();
Response.BinaryWrite(bytes);
Response.End();
}
}
}
}另html:
<asp:DataList id="DataList1" runat="server" DataKeyField="pid" RepeatDirection="Horizontal" RepeatColumns="3">
<ItemTemplate>
<FONT face="宋体"><img src="aa.jpg">
</ItemTemplate>
</asp:DataList>
但无法显示?
提示的错误信息为:
异常详细信息: System.IO.FileNotFoundException: aa.jpg
System.Drawing.Image.FromFile(Server.MapPath(".") + "\\" + "aa.jpg");
如何在Datalist中<ItemTemplet>中imageButton转向另一个页面?
Sub UploadFile(sender As Object, e As EventArgs)If FileUp.PostedFile.ContentLength = 0 Then
FileInfo.Visible = False
Exit Sub
Else
FileInfo.Visible = True
FDisplay1.Visible = True
End IfFSize.Text ="上传文件大小"+ CStr(FileUp.PostedFile.ContentLength/1024)+"KB"
FName.Text = "已上传文件名:"+FileUp.PostedFile.FileName+"<br>"+FName.Text'写入数据库
on error resume next
dim myconn as sqlconnection
dim mycomm as sqlcommand
dim sql as string
dim id as integer
Dim image,anewimage As System.Drawing.Image
dim width,height,newwidth,newheight as integer
Dim callb As System.Drawing.Image.GetThumbnailImageAbort
myConn=New sqlconnection(ConfigurationSettings.AppSettings("数据库"))
myconn.open()
sql="insert into picture (姓名,班级,介绍,属性) values ('"&request.cookies("dgxyl").values("dgxylname")&"','"&request.cookies("dgxyl").values("dgxylbj")&"','"&trim(request("TextBox1"))&"','"&request("r1")&"')"
Mycomm=New sqlcommand(sql,myconn)
mycomm.executenonquery()
myconn.close()Dim myCommand As New SqlCommand("select top 1 id from picture order by id desc", myConn)
myCommand.Connection.Open()
Dim myReader As SqlDataReader=mycommand.executereader()
if myReader.Read() then
id=myReader("id")
end if
myconn.close()
'保存图片
FileUp.PostedFile.SaveAs( Server.MapPath("\classpic\")&cstr(id)&".jpg" )
'生成缩略图
image=System.Drawing.Image.FromFile(Server.MapPath("/classpic/"+cstr(id)+".jpg"))
width=image.Width
height=image.height
if width>height then
newwidth=250
newheight=image.height/image.Width*newwidth
else
newheight=250
newwidth=image.Width/image.height*newheight
end if
response.write("id="+cstr(id)+"width="+cstr(Width)+";height="+cstr(height)+" ")
response.write("newwidth="+cstr(newwidth)+";newheight="+cstr(newheight)+"<br>")aNewImage=image.GetThumbnailImage(newwidth,newheight,callb,new System.IntPtr())
aNewImage.Save(Server.MapPath("/smallpic/"+cstr(id)+".jpg"))
image.Dispose()
Dim FileSplit() As String = Split( FileUp.PostedFile.FileName, "\" )
Dim FileName As String = FileSplit(FileSplit.Length-1)
Dim Exts() As String = Split( FileName, "." )
Dim Ext As String = LCase(Exts(Exts.Length-1))FDisplay.Text = "<A Target='_blank' HREF='/classpic/"&cstr(id)&".jpg"& "'>查看上传文件</A>"
FDisplay1.text="<a href='/picture/default.asp?bj="&cstr(request.cookies("dgxyl").values("dgxylbj"))&"'>返回</a>"
End Sub
</script>
<SCRIPT language=JavaScript>
<!--
var requestsubmitted=false;
function guestbook_Validator(theForm)
{
//检查是否从新提交
if (requestsubmitted==true){
alert("你已经提交了留言,请等待服务器应答!");
return(false);
}
requestsubmitted=true;return (true);
}
//-->
</SCRIPT>
<Html>
<Body BgColor=White>
<H3 align="center">请正确填写下面各项</h3>
<Hr></H3>
<Div id="FileInfo" Visible="False" runat="server">
<Asp:Label id="FSize" runat="server"/><br>
<Asp:Label id="FName" runat="server"/><br>
<Asp:Label id="FDisplay" runat="server"/>
<Asp:Label id="FDisplay1" runat="server"/>
</Div>
<Form Enctype="multipart/form-data" onsubmit="return guestbook_Validator(this)" runat="server">
上传文件
<Input Type="File" id="FileUp" runat="server" size="20"><br>
图片属性:<input type="radio" value="<%=request.cookies("dgxyl").values("dgxylbj")%>" name="R1" checked>本班<input type="radio" value="全校" name="R1">全校(本班则只在本班显示,全校则在全校显示)<P>
图片说明:<br>
<asp:TextBox id="TextBox1" runat="server" Width="233px" Height="141px">
</asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="请输入图片说明">
</asp:RequiredFieldValidator><br>
<Asp:button id="Upload" OnClick="UploadFile" Text="上传图片" runat="server"/>
</form>
<Hr>
<p>注意:</p>
<ol>
<li><b>严禁上传污染环境的照片,否则账号将被删除!</b></li>
<li><font color="#808000"><b>请详细填写照片说明,图片说明不详细将会被视为乱传图片,将会被删除!</b></font></li>
</ol>
<p> </p></Body>
</Html>
<a href="detail.aspx?id=<%# DataBinder.Eval(Container.DataItem, "ImgID")%>" target="_blank">
<img src="showimg.aspx?id=<%# DataBinder.Eval(Container.DataItem, "ImgID")%>" border=0>
</a>
</ItemTemplate>
但无法打开detail.aspx这个页面!