找回密码
 注册
搜索
热搜: 回贴

一个Web文件上传的C#源代码

2009-12-13 13:25| 发布者: admin| 查看: 36| 评论: 0|原作者: 青鸾峰

■//保存文件的路径,包括文件名 priv......


//保存文件的路径,包括文件名
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;


}

最新评论

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 15:27 , Processed in 0.133355 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

返回顶部