VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 网站开发 > ASPnet >
  • ASP+上载例子

作者: 花君   
下面是用ASP+来纺写的上载例子!!在ASP中我们就才上载有许多组件:

<html>

<script language="VB" runat=server>
'VB代码
Sub UploadBtn_Click(Sender as Object, E as EventArgs)
'以test.jpg上载为例
UploadFile.PostedFile.SaveAs(Server.MapPath("test.jpg"))

MyImage.ImageUrl = "test.jpg"

MyImage.Visible = true

End Sub

</script>

<body>

<form enctype="multipart/form-data" runat=server>

<h3>

选择要上载的文件:

<input id="UploadFile" type=file runat=server name="file">

<asp:button text="Upload Me!" onClick="UploadBtn_Click" runat=server/>

<hr>

<asp:image id="MyImage" visible=false runat=server/>

</form>

</body>

</html>

下面是一个更详细的例子,其可以上载文件!还用了 System.Drawing APIs 重新定议了图象, 同时还在图片上加上你的文字,我是用 C#编写的 -- 你也可以用VB、Jscript来写。

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>

<html>

<script language="C#" runat=server>

void UploadBtn_Click(Object sender, EventArgs e)
{
UploadFile.PostedFile.SaveAs(Server.MapPath("test.jpg"));
ImageEditor.Visible = true;
}

void UpdateBtn_Click(Object sender, EventArgs e)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("test.jpg"));
System.Drawing.Image newimage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppRGB);
Graphics g = Graphics.FromImage(newimage);
g.DrawImage(image,0,0,image.Width,image.Height);
Font f = new Font("Lucida Sans Unicode", Int32.Parse(FontSize.SelectedItem.Text));
Brush b = new SolidBrush(Color.Red);
g.DrawString(Caption.Text, f, b, 10, 140);
g.Dispose();
System.Drawing.Image thumbImage = newimage.GetThumbnailImage(Int32.Parse(Width.Text),Int32.Parse(Height.Text),null,0);
image.Dispose();
thumbImage.Save(Server.MapPath("test.jpg"), ImageFormat.JPEG);
}

</script>

<body>

<form enctype="multipart/form-data" runat=server>

<h3>

选择要上载的文件:
<input id="UploadFile" type=file runat=server name="file2">

<asp:button text="Upload Me!" onClick="UploadBtn_Click" runat=server/>

<hr>
<asp:panel id="ImageEditor" visible=false runat=server>
<img src="test.jpg">
<h3>
图象的宽度: <asp:textbox id="Width" runat=server/>
图象的高度: <asp:textbox id="Height" runat=server/>
<br>
文字的内容: <asp:textbox id="Caption" runat=server/>
文字的大小: <asp:dropdownlist id="FontSize" runat=server>
<asp:listitem>14</asp:listitem>
<asp:listitem>18</asp:listitem>
<asp:listitem>26</asp:listitem>
<asp:listitem>36</asp:listitem>
<asp:listitem>48</asp:listitem>
<asp:listitem>62</asp:listitem>
</asp:dropdownlist>
<asp:button text="Update Image" onClick="UpdateBtn_Click" runat=server/>
</h3>
</asp:panel>
</form>
</body>
</html >

 


相关教程