导读:
//保存文件的路径,包括文件名
private string GetSavePath(string FileName)
{
string path=Request.PhysicalApplicationPath +"\\Link_Icon";
return path+"\\"+FileName
}
private bool UpLoad()//上传图片
{
bool flag=false;
string FileName=GetFileName(fileIcon.Value );
string db=Request.PhysicalApplicationPath+"\\#CommCcope.mdb";
string constr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+db;
OleDbConnection con=new OleDbConnection (constr);
try
{
//上传文件
string SavePath=GetSavePath(FileName);
fileIcon .PostedFile.SaveAs (SavePath);
//插入数据库
OleDbCommand com=new OleDbCommand ("Insert into FriendLink(SiteName,DISPLAY,LINK) VALUES('"+txtName.Text +"','"+FileName+"','"+txtLink.Text +"')",con);
con.Open ();
com.ExecuteNonQuery ();
con.Close ();
flag =true;
}
catch(Exception ex)
{
Label1 .Text ="错误:"+ex.Message ;
}
finally
{
if(con.State !=0)con.Dispose ();
}
return flag;
}
本文转自
http://study.qqcf.com/web/224/24039.htm
//保存文件的路径,包括文件名
private string GetSavePath(string FileName)
{
string path=Request.PhysicalApplicationPath +"\\Link_Icon";
return path+"\\"+FileName
}
private bool UpLoad()//上传图片
{
bool flag=false;
string FileName=GetFileName(fileIcon.Value );
string db=Request.PhysicalApplicationPath+"\\#CommCcope.mdb";
string constr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+db;
OleDbConnection con=new OleDbConnection (constr);
try
{
//上传文件
string SavePath=GetSavePath(FileName);
fileIcon .PostedFile.SaveAs (SavePath);
//插入数据库
OleDbCommand com=new OleDbCommand ("Insert into FriendLink(SiteName,DISPLAY,LINK) VALUES('"+txtName.Text +"','"+FileName+"','"+txtLink.Text +"')",con);
con.Open ();
com.ExecuteNonQuery ();
con.Close ();
flag =true;
}
catch(Exception ex)
{
Label1 .Text ="错误:"+ex.Message ;
}
finally
{
if(con.State !=0)con.Dispose ();
}
return flag;
}
本文转自
http://study.qqcf.com/web/224/24039.htm
本文介绍了一个简单的文件上传方法及如何将文件信息保存到数据库的过程。具体实现了获取文件保存路径、上传文件并更新数据库记录的功能。

被折叠的 条评论
为什么被折叠?



