设为首页
加入收藏
站内地图
旧版入口
当前位置:首页 > 站长学院 > 网络编程 > C#

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

作者:佚名 出处:网络转载 时间:04-15 点击:

内容载入中...
//保存文件的路径,包括文件名
  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;
   
  
  }


收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口

站长学院

推荐信息