1个回答
展开全部
<table id="tabFU" runat ="server" enableviewstate ="true" cellpadding ="0" cellspacing ="0">
<tr>
<td class="style1" >
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
</table>
<div class="ubt"><asp:Button ID="btnUp" runat="server" Text="上传所有文件"
OnClick="btnUp_Click" Width="94px" />
//////后台
//调用GetAutoID方法获取上传文件自动编号
int IntFieldID = CC.GetAutoID("id", "filelist");
//文件的真实名(格式:[文件编号]上传文件名)
//用于实现上传多个相同文件时,原有文件不被覆盖
string strFileTName = +IntFieldID + System.IO.Path.GetFileName(UserHPF.FileName);
//定义插入字符串,将上传文件信息保存在数据库中
string sqlStr = "insert into filelist(id,f_name,f_path,uptime,f_truename,f_ower,f_type)";
sqlStr += "values('" + IntFieldID + "'";
sqlStr += ",'" + System.IO.Path.GetFileName(UserHPF.FileName) + "'";
sqlStr += ",'" + realpath + "'";
sqlStr += ",'" + DateTime.Now.ToShortDateString().ToString() + "'";
sqlStr += ",'" + strFileTName + "'";
sqlStr += ",'" + Session["UserID"].ToString() + "'";
sqlStr += ",'" + fl + "')";
//打开与数据库的连接
SqlConnection myConn = CC.GetCon();
myConn.Open();
SqlCommand myCmd = new SqlCommand(sqlStr, myConn);
myCmd.ExecuteNonQuery();
myCmd.Dispose();
myConn.Dispose();
//将上传的文件存放在指定的文件夹中
UserHPF.SaveAs(FilePath + "//" + strFileTName);
<tr>
<td class="style1" >
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
</table>
<div class="ubt"><asp:Button ID="btnUp" runat="server" Text="上传所有文件"
OnClick="btnUp_Click" Width="94px" />
//////后台
//调用GetAutoID方法获取上传文件自动编号
int IntFieldID = CC.GetAutoID("id", "filelist");
//文件的真实名(格式:[文件编号]上传文件名)
//用于实现上传多个相同文件时,原有文件不被覆盖
string strFileTName = +IntFieldID + System.IO.Path.GetFileName(UserHPF.FileName);
//定义插入字符串,将上传文件信息保存在数据库中
string sqlStr = "insert into filelist(id,f_name,f_path,uptime,f_truename,f_ower,f_type)";
sqlStr += "values('" + IntFieldID + "'";
sqlStr += ",'" + System.IO.Path.GetFileName(UserHPF.FileName) + "'";
sqlStr += ",'" + realpath + "'";
sqlStr += ",'" + DateTime.Now.ToShortDateString().ToString() + "'";
sqlStr += ",'" + strFileTName + "'";
sqlStr += ",'" + Session["UserID"].ToString() + "'";
sqlStr += ",'" + fl + "')";
//打开与数据库的连接
SqlConnection myConn = CC.GetCon();
myConn.Open();
SqlCommand myCmd = new SqlCommand(sqlStr, myConn);
myCmd.ExecuteNonQuery();
myCmd.Dispose();
myConn.Dispose();
//将上传的文件存放在指定的文件夹中
UserHPF.SaveAs(FilePath + "//" + strFileTName);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询