62,041
社区成员
发帖
与我相关
我的任务
分享
protected void btnUpload_Click(object sender, EventArgs e)
{
string fullname = this.fu.PostedFile.FileName.ToString();
if (fullname.Length > 0)
{
FileInfo f = new FileInfo(fullname);
string fname = f.Name.ToString();//获取原始文件名称
string f_ex = f.Extension.ToString().ToLower();//获取文件的类型
string length = f.Length.ToString();//获取文件的大小
string newname = DateTime.Now.Millisecond.ToString() + length + fname;//定义文件的新名称用于保存在服务器上
string savepath = Server.MapPath("annex");//文件存储的路径
fu.SaveAs(savepath + "\\" + newname);//将以新文件名保存到服务器上
string scf01x = msg.addscf(newname,f_ex, savepath, fname);
if (scf01x.Length > 0)
{
this.lblOldName.Text = fname;
this.t_newname.Text = scf01x;
this.lblMsg.Text = "----<font color=green>上传成功!</font>";
this.btnUpload.Enabled = false;
// this.btnClose.Disabled = false;
if (f_ex.Trim() == ".jpg")
{
this.im_fujian.Visible = true;
//im_fujian.ImageUrl = savepath.Trim() + "\\" + newname.Trim();
im_fujian.ImageUrl = "annex/" + newname.Trim();
strimg = this.im_fujian.ImageUrl;
}
}
else
{
this.lblMsg.Text = "----<font color=green>上传失败!</font>";
}
}
else
{
this.lblMsg.Text = "----<font color=red>请选择上传的附件!</font>";
}
scf01 = this.t_newname.Text;
oldname = this.lblOldName.Text;
}
<input type="text" runat="server" id="funame" name="funame" value="单击上传...." readonly="readonly" onclick="op(this);"/>
function op()
{
window.open('fujian.aspx','x','height=320,width=400')
}
<head runat="server">
<title>莱克信息发布平台_上传附件</title>
<link rel="stylesheet" href="css/css.css" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function tj(scf,oldname)
{
if (scf =="")
{
alert("您还没上传附件!---选择附件后请点提交!");
return false
}
if (scf !="")
window.opener.document.getElementById("t_scb07").value=scf;
window.opener.document.getElementById("funame").value=oldname;
window.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table cellpadding="0" cellspacing="0" border="0" style="margin-top:12px;">
<tr>
<td> 上传附件:</td>
<td style="text-align:center; line-height:40px; height:40px;"><asp:FileUpload ID="fu" runat="server" Width="198px" Height="23px" />
<asp:Button ID="btnUpload" runat="server" Text=" 上 传 " OnClick="btnUpload_Click" /></td>
</tr>
<tr>
<td colspan="2" style="text-align:center; line-height:40px; height:40px;">
<input type="button" value=" 提 交 " id="btnClose" onclick="tj('<%=scf01 %>','<%=oldname %>');" />
</td>
</tr>
</table>
<asp:TextBox runat="server" ID="t_newname" Visible="false"></asp:TextBox>
<asp:Label ID="lblOldName" runat="server"></asp:Label>
<asp:Label ID="lblMsg" runat="server"></asp:Label>
<a href="<%=strimg %>" target="_blank">
<asp:Image runat="server" ID="im_fujian" Visible="false" ToolTip="点击查看大图" Width="164" Height="112" />
</a>
</form>
</body>
</html>