手揣网教程:绿色安全纯净官方版,体验当今速度最快的浏览器!

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

时间:2024/12/17作者:未知来源:手揣网教程人气:

[摘要]//保存文件的路径,包括文件名 private string GetSavePath(string FileName) string path=Request.PhysicalApplica...
//保存文件的路径,包括文件名
  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;
   
  
  }




关键词:一个Web文件上传的C#源代码




Copyright © 2012-2018 手揣网教程(http://www.shouchuai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版