Asp.net 文件上传(Vb.net版)
在Asp.net中实现文件的上传功能,是非常简单的一件事情,只需要利用微软提供的FileUpload控件即可轻松实现。
LargeFileUpload.aspx代码如下
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="LargeFileUpload.aspx.vb"
Inherits="LargeFileUpload" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Upload LargeFile</title>
</head>
<body>
<form id="form1" runat="server" enctype="multipart/form-data">
<! 注意在form中必须有enctype="multipart/form-data",表示表单中有上传文件,否则文件无法上传>
<div>
<center>
<asp:FileUpload ID="FileUpload1" runat="server" Width="336px" /><br />
<!runat="server" 表示此控件是服务器控件>
<asp:Button ID="btnUpload" runat="server" Text="Upload" />
<asp:Button ID="btnReset" runat="server" Text="Reset" />
</center>
</div>
</form>
</body>
</html>LargeFileUpload.aspx.vb代码如下:Partial Class LargeFileUpload
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Me.IsPostBack Then
'Upload file
Call UploadFiles()
End If
End Sub
Private Sub UploadFiles()
Try
相关文档:
1. 打开新的窗口并传送参数:
传送参数:
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>")
接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
2.为按钮添加对话框
Button1.Attribute ......
ASP.NET程序中常用代码汇总
1.自定义异常处理
//自定义异常处理类
using System;
using System.Diagnostics;
namespace MyAppException
{
/// <summary>
/// 从系统异常类ApplicationException继承的应用程序异常处理类。
/// 自动将异常内容记录到Windows NT/2000的应用程序日志
/// </summary>
......
有人也问了个在线统计的问题,我的见意是这样的:
在Application_Start事件中加入以下代码:
Application.Lock();
Application.["UserCount"]=0;
Application.Unlock();
Session_Start事� ......
无意中发现VB For循环的一个特点:在循环体中,企图改变循环终止变量使之提前退出循环是徒劳的。
Private Sub Form_Load()
Dim s(0 To 4) As String
Dim N As Integer, i As Integer
s(0) = "测试1"
s(1) = "测试2"
s(2) = "测试3"
s(3) = "测试4"
s(4) = "测试5 ......