Posted on
2006-06-21 13:29Bobby
阅读(355)
评论(0)
收藏举报
Imports System Imports System.Web Imports System.Drawing Imports System.IO Imports System.Web.HttpPostedFile Imports System.Drawing.Imaging PublicClass lytpClass lytp Inherits System.Web.UI.Page ProtectedWithEvents lblfile As System.Web.UI.WebControls.Label ProtectedWithEvents Button1 As System.Web.UI.WebControls.Button ProtectedWithEvents txt_name1 As System.Web.UI.WebControls.TextBox ProtectedWithEvents txt_w As System.Web.UI.WebControls.TextBox ProtectedWithEvents txt_rename As System.Web.UI.WebControls.TextBox ProtectedWithEvents txt_h As System.Web.UI.WebControls.TextBox ProtectedWithEvents txt_name2 As System.Web.UI.WebControls.TextBox ProtectedWithEvents txt_name3 As System.Web.UI.WebControls.TextBox ProtectedWithEvents file As System.Web.UI.HtmlControls.HtmlInputFile Web Form Designer Generated Code#Region " Web Form Designer Generated Code " <System.Diagnostics.DebuggerStepThrough()>PrivateSub InitializeComponent()Sub InitializeComponent() End Sub PrivateSub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Init InitializeComponent() End Sub #End Region PrivateSub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load Button1.Text ="上传图片" '传递参数 txt_name1.Text = Request.QueryString("lja") txt_name2.Text = Request.QueryString("ljb") txt_name3.Text = Request.QueryString("ljc") txt_w.Text = Request.QueryString("tpw") txt_h.Text = Request.QueryString("tph") txt_rename.Text = Request.QueryString("tpmc") End Sub PrivateSub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '创建文件夹 Dim Path1 AsString= Server.MapPath(txt_name1.Text) Dim Path2 AsString= Server.MapPath("../"+"lytp"+"/"+ txt_name1.Text +"/"+ txt_name2.Text) Dim Path3 AsString= Server.MapPath("../"+"lytp"+"/"+ txt_name1.Text +"/"+ txt_name2.Text +"/"+ txt_name3.Text) Try If txt_name1.Text =""Or txt_name2.Text =""Or txt_name3.Text =""Then lblfile.Text ="请输入文件夹名称" Else If (Directory.Exists(Path1)) Or (Directory.Exists(Path2)) Or (Directory.Exists(Path3)) Then lblfile.Text ="此文件夹已经存在了" Else Directory.CreateDirectory(Path1) Directory.CreateDirectory(Path2) Directory.CreateDirectory(Path3) lblfile.Text ="已经创建文件夹" EndIf EndIf Catch lblfile.Text ="新建文件夹错误" Finally EndTry Dim MyFileColl As HttpFileCollection = HttpContext.Current.Request.Files Dim MyPostedFile As HttpPostedFile = MyFileColl.Item(0) Dim x AsInteger Dim y AsInteger '定义图片的长和宽 x = txt_w.Text y = txt_w.Text IfLCase(MyPostedFile.ContentType.ToString()).IndexOf("image") <0Then lblfile.Text ="无效的图形格式。" Exit Sub EndIf GetThumbNail(MyPostedFile.FileName, x, y, MyPostedFile.ContentType.ToString(), False, MyPostedFile.InputStream) Dim fileFullname AsString= file.PostedFile.FileName '取文件扩展名 Dim fileName AsString= fileFullname.Substring(fileFullname.LastIndexOf("\") +1) Dim type AsString= fileFullname.Substring(fileFullname.LastIndexOf(".") +1) file.PostedFile.SaveAs(Server.MapPath("../"+"lytp"+"/"+ txt_name1.Text +"/"+ txt_name2.Text +"/"+ txt_name3.Text) +"\"+ txt_rename.Text +"_d."+ type) Response.Write("<script>window.opener=null;window.close()</script>") End Sub PrivateFunction GetImageType()Function GetImageType(ByVal strContentType) As System.Drawing.Imaging.ImageFormat '图片格式的处理 SelectCase (strContentType.ToString().ToLower()) Case"image/pjpeg" GetImageType = System.Drawing.Imaging.ImageFormat.Jpeg Case"image/gif" GetImageType = System.Drawing.Imaging.ImageFormat.Gif Case"image/bmp" GetImageType = System.Drawing.Imaging.ImageFormat.Bmp Case"image/tiff" GetImageType = System.Drawing.Imaging.ImageFormat.Tiff Case"image/x-icon" GetImageType = System.Drawing.Imaging.ImageFormat.Icon Case"image/x-png" GetImageType = System.Drawing.Imaging.ImageFormat.Png Case"image/x-emf" GetImageType = System.Drawing.Imaging.ImageFormat.Emf Case"image/x-exif" GetImageType = System.Drawing.Imaging.ImageFormat.Exif Case"image/x-wmf" GetImageType = System.Drawing.Imaging.ImageFormat.Wmf CaseElse GetImageType = System.Drawing.Imaging.ImageFormat.MemoryBmp EndSelect End Function PrivateSub GetThumbNail()Sub GetThumbNail(ByVal strFileName, ByVal iWidth, ByVal iheight, ByVal strContentType, _ ByVal blnGetFromFile, ByVal ImgStream) '缩略图片处理 Dim oImg As Image If blnGetFromFile Then oImg = oImg.FromFile(strFileName) Else oImg = oImg.FromStream(ImgStream) EndIf oImg = oImg.GetThumbnailImage(iWidth, iheight, Nothing, (New IntPtr).Zero) Dim strGuid AsString= (New Guid).NewGuid().ToString().ToUpper() Dim strFileExt AsString= strFileName.Substring(strFileName.LastIndexOf(".")) oImg.Save(Server.MapPath("../"+"lytp"+"/"+ txt_name1.Text +"/"+ txt_name2.Text +"/"+ txt_name3.Text) +"\"+ txt_rename.Text +"_x"+ strFileExt, GetImageType(strContentType)) End Sub End Class
PublicClass WebForm1Class WebForm1 Inherits System.Web.UI.Page Web 窗体设计器生成的代码#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。 <System.Diagnostics.DebuggerStepThrough()>PrivateSub InitializeComponent()Sub InitializeComponent() End Sub ProtectedWithEvents Label1 As System.Web.UI.WebControls.Label ProtectedWithEvents Label2 As System.Web.UI.WebControls.Label ProtectedWithEvents Label3 As System.Web.UI.WebControls.Label ProtectedWithEvents TextBox1 As System.Web.UI.WebControls.TextBox ProtectedWithEvents TextBox2 As System.Web.UI.WebControls.TextBox ProtectedWithEvents TextBox3 As System.Web.UI.WebControls.TextBox ProtectedWithEvents Button1 As System.Web.UI.WebControls.Button ProtectedWithEvents TextBox4 As System.Web.UI.WebControls.TextBox ProtectedWithEvents TextBox5 As System.Web.UI.WebControls.TextBox ProtectedWithEvents TextBox6 As System.Web.UI.WebControls.TextBox ProtectedWithEvents Label4 As System.Web.UI.WebControls.Label ProtectedWithEvents Label5 As System.Web.UI.WebControls.Label ProtectedWithEvents Label6 As System.Web.UI.WebControls.Label '注意: 以下占位符声明是 Web 窗体设计器所必需的。 '不要删除或移动它。 Private designerPlaceholderDeclaration As System.Object PrivateSub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Init 'CODEGEN: 此方法调用是 Web 窗体设计器所必需的 '不要使用代码编辑器修改它。 InitializeComponent() End Sub #End Region PrivateSub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load '在此处放置初始化页的用户代码 End Sub PrivateSub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim url AsString Dim v1 AsString '把输入的内容传递给index.aspx url ="index.aspx?lja="+ TextBox1.Text +"&ljb="+ TextBox2.Text +"&ljc="+ TextBox3.Text +"&tpw="+ TextBox4.Text +"&tpmc="+ TextBox6.Text Response.Redirect(url) End Sub End Class