62,025
社区成员
发帖
与我相关
我的任务
分享
public partial class admin_UpSoft : System.Web.UI.Page
{
CAN can = new CAN();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
string filepath = "", fileExtName = "", mFileName,mPath;
if ("" != this.File2.PostedFile.FileName)
{
filepath=File2 .PostedFile.FileName;
fileExtName= filepath.Substring(filepath.LastIndexOf(".")+1);
try
{
mPath=Server.MapPath("..\\FileDown\\");
mFileName=filepath .Substring(filepath.LastIndexOf("\\")+1);
File2.PostedFile .SaveAs(mPath+mFileName);
TextBox2 .Text ="FileDown\\"+mFileName;
File2.Visible=false;
TextBox2.Visible=true;
}
catch(Exception err)
{
Response.Write(err.ToString());
}
}
can.ExecSqlCom("Insert into Soft(SoftName,DownLoad) values('" + TextBox1.Text + "','" + TextBox2.Text + "')");
Response.Write("<script language=javascript>alert('上传成功!');location='javascript:history.go(-1)'</script>");
}
protected void Button1_Click(object sender, EventArgs e)
{
Page.Response.Redirect("main.aspx");
}
protected void btnUpload_Click(object sender, EventArgs e)
{
//判断是否上传了文件
if (fileUpload.HasFile)
{
//指定上传文件在服务器上的保存路径
string savePath = Server.MapPath("~/upload/");
//检查服务器上是否存在这个物理路径,如果不存在则创建
if (!System.IO.Directory.Exists(savePath))
{
//需要注意的是,需要对这个物理路径有足够的权限,否则会报错
//另外,这个路径应该是在网站之下,而将网站部署在C盘却把上传文件保存在D盘
System.IO.Directory.CreateDirectory(savePath);
}
savePath = savePath + "\\" + fileUpload.FileName;
fileUpload.SaveAs(savePath);//保存文件
//不过需要注意的是,在客户端访问却需要指定的是URL地址,而不是在服务器上的物理地址
literal.Text = string.Format("<a href='upload/{0}'>upload/{0}</a>", fileUpload.FileName);
}
}