<input id="file1" type="file" name="file1" runat="server">
<asp:button id="btn_upload" runat="server" Text="上传"></asp:button>private void btn_upload_Click(object sender, System.EventArgs e)
{
string spath = Server.MapPath(".")+"\\Upload";
try
{
if(Directory.Exists(spath))
Directory.Delete(spath,true);
Directory.CreateDirectory(spath); string filename = file1.PostedFile.FileName;
if(filename != "")
{
filename = filename.Substring(filename.LastIndexOf("\\")+1);
file1.PostedFile.SaveAs(Path.Combine(spath,Path.GetFileName(filename)));
} this.Response.Write("<script>alert('上传完成!')</script>");
}
catch(Exception ex)
{
this.Response.Write("<script>alert('上传失败!')</script>");
}
}
<asp:button id="btn_upload" runat="server" Text="上传"></asp:button>private void btn_upload_Click(object sender, System.EventArgs e)
{
string spath = Server.MapPath(".")+"\\Upload";
try
{
if(Directory.Exists(spath))
Directory.Delete(spath,true);
Directory.CreateDirectory(spath); string filename = file1.PostedFile.FileName;
if(filename != "")
{
filename = filename.Substring(filename.LastIndexOf("\\")+1);
file1.PostedFile.SaveAs(Path.Combine(spath,Path.GetFileName(filename)));
} this.Response.Write("<script>alert('上传完成!')</script>");
}
catch(Exception ex)
{
this.Response.Write("<script>alert('上传失败!')</script>");
}
}
解决方案 »
- webserver里,怎么引用过滤器来进行判断是否登录过
- int强制转换成枚举类型,报错?急,在线结贴。
- 写了一个C#数据库类的代码生成器,希望对初学者有用,大家多提意见
- 不好意思,又遇到问题了,关于innerHTML和cs问题
- 求救:::FolderNameEditor类怎么用?帮看一下代码~~ 没分了 就10分了 谢谢大家!!!
- 急!!高分(100)请教一个关于IIS日志记录时间问题
- datagrid中的删除和分页问题!(VB)
- 如何获取到元素?
- 哪位朋友有“ 征服ASP.NET Ajax典型应用”的源代码发给我一份好吗?
- 怎样把下面的程序改成codebehind,新手,谢谢
- 关于TreeView的问题
- 请教:IIS服务信息服务管理器无法打开了 所有的.msc文件都无法运行 该如何解决?
this.hldown.Visible = true;