using System.Web.Security;
//上传文件
private void Button2_ServerClick(object sender, System.EventArgs e)
{
HttpPostedFile hpf = htmlfile.PostedFile;
char[] de = {'\\'};
string[] file1 = hpf.FileName.Split( de );
string file2 = file1[ file1.Length - 1 ];hpf.SaveAs( Server.MapPath("/mail") + "\\" + file2 );
}
<INPUT id="htmlfile" type="file" name="htmlfile" runat="server"><INPUT id="Button2" title="上传文件" type="button" value="上传文件" name="Button2" runat="server">
//上传文件
private void Button2_ServerClick(object sender, System.EventArgs e)
{
HttpPostedFile hpf = htmlfile.PostedFile;
char[] de = {'\\'};
string[] file1 = hpf.FileName.Split( de );
string file2 = file1[ file1.Length - 1 ];hpf.SaveAs( Server.MapPath("/mail") + "\\" + file2 );
}
<INPUT id="htmlfile" type="file" name="htmlfile" runat="server"><INPUT id="Button2" title="上传文件" type="button" value="上传文件" name="Button2" runat="server">
解决方案 »
- windows server 2008 + Sql2008 集群虚拟磁盘用什么软件?
- DropDownList的值为什么在提交按钮点击后会回到初始项?
- 如何获取ASP中radio的值
- 如何让按钮响应回车
- 如何做权限管理!?
- 除了Web.config,还有什么方法记录不重要的信息
- 英文版windows2003+IIS6,asp.net页面中文字符显示不正常,很多问号
- 如何更改文本框回车默认处理?
- 请开发过组件的老大们指点指点,如何开发组件!!!
- VS.net安装时出现25003错误谁能帮忙解决.急
- 高分求产品展示的asp.net C#代码!分不够的话在加!
- [共享]如何产生表头(Fix title)固定的DataGrid(数据网格控件)
<INPUT id="File1" type="file" size="50" name="File1" runat="server">
<asp:button id="btn_Upfile" runat="server" Text="上传"></asp:button>
aspx.vb文件
Private Function UpFile() As Boolean
Dim filena As String = Path.GetFileName(File1.PostedFile.FileName)
Dim filesm As String = Me.tbx_Upfile.Text.Trim
If Len(filena) > 0 And Len(filesm) > 0 Then
Dim filepath As String = Server.MapPath("../fileupLoad/" + filena)
UpfilePath = "../fileupLoad/" + Path.GetFileName(File1.PostedFile.FileName)
If (File.Exists(filepath)) Then
lbl_error.Text = "上传文件重名,请改名后再上传!"
Return False
Else
If Not (File1.PostedFile Is Nothing) Then
Try
File1.PostedFile.SaveAs(filepath)
lbl_error.Text = "<b>成功上传!</b>"
Return True
Catch ex As Exception
lbl_error.Text = "保存文件时出错<b>"
Return False
End Try End If
End If
Else
Me.lbl_error.Text = "请先输入附件说明或者选择要上传的附件!"
Exit Function
End If End Function
{
if(this.myFile.PostedFile!=null) //upload textbox
{
//接收路径
string strPath=Request.QueryString["path"]; //current direction //如果接收的路径为空,则获取当前路径
if(strPath==null)
{
strPath=Request.ServerVariables["APPL_PHYSICAL_PATH"];
}
else
{
if(strPath.Substring(strPath.Length-1,1)!="\\")
{
strPath=strPath+"\\";
}
} //处理字符串
string strName=this.myFile.PostedFile.FileName;
int i=strName.LastIndexOf("\\");
string strNewName=strName.Substring(i);
string strFullName=strPath+strNewName;
//保存文件
this.myFile.PostedFile.SaveAs(strFullName);
//Response.Redirect("index.aspx?path="+strPath);
this.Label2.Text="<center><font color=red>上传成功</font></center>";
ListFile();
}
}