這裡有一個怎樣用ASP+上傳文件的非常簡單例子
<HTML>
<script language=VB runat=server>
Sub UploadBtn_Click(Sender as Object E as EventArgs)
UploadFilePostedFileSaveAs(ServerMapPath(testjpg))
MyImageImageUrl = testjpg
MyImageVisible = true
End Sub
</script>
<body>
<form enctype=multipart/formdata runat=server>
<h>
選擇上傳文件: <input id=UploadFile type=file runat=server>
<asp:button Text=Upload Me! OnClick=UploadBtn_Click runat=server/>
<hr>
<asp:image id=MyImage Visible=false runat=server/>
</form>
</body>
</html>
Here is a more complex example which enables you to upload a file and then using the SystemDrawing APIs
to resize/crop the image overlay a custom text message onto the image and then save it back out to disk
as a jpg (note that this sample works with *any* browser) Ive written this one in C# but you would
obviously be able to use VB or JScript to do it as well:
<%@ Import Namespace=SystemIO %>
<%@ Import Namespace=SystemDrawing %>
<%@ Import Namespace=SystemDrawingImaging %>
<html>
<script language=C# runat=server>
void UploadBtn_Click(Object sender EventArgs e) {
UploadFilePostedFileSaveAs(ServerMapPath(testjpg));
ImageEditorVisible = true;
}
void UpdateBtn_Click(Object sender EventArgs e) {
SystemDrawingImage image = SystemDrawingImageFromFile(ServerMapPath(testjpg));
SystemDrawingImage newimage = new Bitmap(imageWidth imageHeight PixelFormatFormatbppRGB);
Graphics g = GraphicsFromImage(newimage);
gDrawImage(imageimageWidthimageHeight);
Font f = new Font(Lucida Sans Unicode IntParse(FontSizeSelectedItemText));
Brush b = new SolidBrush(ColorRed);
gDrawString(CaptionText f b );
gDispose();
SystemDrawingImage thumbImage = newimageGetThumbnailImage(IntParse(WidthText)IntParse
(HeightText)null);
imageDispose();
thumbImageSave(ServerMapPath(testjpg) ImageFormatJPEG);
}
</script>
<body>
<form enctype=multipart/formdata runat=server>
<h>
Select File To Upload: <input id=UploadFile type=file runat=server>
<asp:button Text=Upload Me! OnClick=UploadBtn_Click runat=server/>
<hr>
<asp:panel id=ImageEditor Visible=false runat=server>
<img src=testjpg>
<h>
Image Width: <asp:textbox id=Width runat=server/>
Image Height: <asp:textbox id=Height runat=server/> <br>
Text Caption: <asp:textbox id=Caption runat=server/>
Caption Size: <asp:dropdownlist id=FontSize runat=server>
<asp:listitem></asp:listitem>
<asp:listitem></asp:listitem>
<asp:listitem></asp:listitem>
<asp:listitem></asp:listitem>
<asp:listitem></asp:listitem>
<asp:listitem></asp:listitem>
</asp:dropdownlist>
<asp:button Text=Update Image OnClick=UpdateBtn_Click runat=server/>
</h>
</asp:panel>
</form>
</body>
</html>
From:http://tw.wingwit.com/Article/program/ASP/201405/30974.html