http://www.sjtvu.com/dreamnetstudio/ArticleView.aspx?id=14,都是按照这个地址来的,可是里面有段代码是C语言,我想知道用VB语言应该怎么写,就是这段
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null)
{
string strDir = FileUpload1.PostedFile.FileName;
int myPos = strDir.LastIndexOf("\\");
string strFileName = strDir.Substring(myPos);
string strPath = Server.MapPath(".") + strFileName;
this.Label1.Text = "保存路径:";
this.Label1.Text += strPath;
FileUpload1.PostedFile.SaveAs(strPath);
this.Label1.Text += "文件名称:";
this.Label1.Text += FileUpload1.PostedFile.FileName;
this.Label1.Text += "文件类型:";
this.Label1.Text += FileUpload1.PostedFile.ContentType;
this.Label1.Text += "文件大小:";
this.Label1.Text += FileUpload1.PostedFile.ContentLength.ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null)
{
string strDir = FileUpload1.PostedFile.FileName;
int myPos = strDir.LastIndexOf("\\");
string strFileName = strDir.Substring(myPos);
string strPath = Server.MapPath(".") + strFileName;
this.Label1.Text = "保存路径:";
this.Label1.Text += strPath;
FileUpload1.PostedFile.SaveAs(strPath);
this.Label1.Text += "文件名称:";
this.Label1.Text += FileUpload1.PostedFile.FileName;
this.Label1.Text += "文件类型:";
this.Label1.Text += FileUpload1.PostedFile.ContentType;
this.Label1.Text += "文件大小:";
this.Label1.Text += FileUpload1.PostedFile.ContentLength.ToString();
}
}
解决方案 »
- asp.net网站访问量
- 关于popupWin的一个问题
- asp.net怎么定时杀死指定的进程
- 怎么样将datalist控件的长日期格式字段显示为短日期格式的????
- VS2003无法调试。找不到IE浏览器怎么办?
- CustomValidator控件的ServerValiate事件怎么找不到?
- 取用户控件里面值的问题
- 求救啊高手~ 关于ConnectionString 属性尚未初始化
- (C#)asp.net中如何成功发送email
- DropDownList 设置默认值的问题
- 用GridView 点击首页 上一页 下一页 尾页 触发PageIndexChange事件
- 错误 CS0019: 运算符“+”无法应用于“string”和“方法组”类型的操作数
If FileUpload1.PostedFile <> Nothing Then
Dim strDir As String = FileUpload1.PostedFile.FileName
Dim myPos As Integer = strDir.LastIndexOf("\")
Dim strFileName As String = strDir.Substring(myPos)
Dim strPath As String = Server.MapPath(".") + strFileName
Me.Label1.Text = "保存路径:"
Me.Label1.Text += strPath
FileUpload1.PostedFile.SaveAs(strPath)
Me.Label1.Text += "文件名称:"
Me.Label1.Text += FileUpload1.PostedFile.FileName
Me.Label1.Text += "文件类型:"
Me.Label1.Text += FileUpload1.PostedFile.ContentType
Me.Label1.Text += "文件大小:"
Me.Label1.Text += FileUpload1.PostedFile.ContentLength.ToString()
End If
End Sub
Dim strFileName As String = strDir.Substring(myPos)出现 StartIndex 不能小于 0。 参数名: startIndex
<%@ Import Namespace="System.Web.HttpPostedFile" %>
<%@ Import Namespace="System.Web.UI.HtmlControls.HtmlInputFile" %>
<script language="VB" runat="server">
Sub UpLoad(Src As Object, E As EventArgs)
If UploadFile.PostedFile.ContentLength=0 then
ShowUpLoadFile.innerText="上传失败或文件不存在!"
Else
'获取文件名
dim Temp() as String=Split(UploadFile.PostedFile.FileName,"\")
dim FileName as String=Temp(Temp.Length-1)
'保存文件
UploadFile.PostedFile.SaveAs(Server.MapPath(".") & "\Files\" & FileName)
'显示上传结果
ShowUpLoadFile.InnerHtml="文件上传成功!<br>上传文件名:" & FileName
End If
End Sub
</script>
<html>
<body>
<form runat="server" enctype="multipart/form-data">
<input type="file" id="UploadFile" runat="server" size="50"><br>
<asp:button runat="server" Text="立即上传" onClick="Upload" />
</form>
<hr><br>
<span id="ShowUpLoadFile" runat="server"></span>
</body>
</html>