ITPub博客

首页 > 应用开发 > IT综合 > 一个Web文件上传的C#源代码

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

原创 IT综合 作者:BugRobber 时间:2007-06-23 14:55:28 0 删除 编辑
//保存文件的路径,包括文件名
private string GetSavePath(string FileName)
{
string path=Request.PhysicalApplicationPath +"";
return path+""+FileName;
}

private bool UpLoad()//上传图片
{
bool flag=false;
string FileName=GetFileName(fileIcon.Value );
string db=Request.PhysicalApplicationPath+"";
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;


}

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8781179/viewspace-920696/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    372
  • 访问量
    200892