一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

asp.net C#(HtmlInputFile)上传图片代码

时间:2011-03-12 编辑:简简单单 来源:一聚教程网

asp教程.net c#(htmlinputfile)上传图片代码

先看一下htmlinputfile文件上传功能
 
httpfilecollection   files     =   httpcontext.current.request.files;
if   (   files.count   ==   1   )
{
      httppostedfile   postedfile   =   files[0];
      if   (   postedfile.filename   !=   " "   )
      {
            string   filename   =   path.getextension(postedfile.filename);
            string   savepath   =   "/upload/ "   +   filename;
            try
            {
postedfile.saveas(savepath);
            }
            catch
            {
this.showmessage( "上传照片失败! ");
throw;
            }
    }
}


下面一款应用实例
%@page language="c#" %>
<%@import namespace="system.io"%>
<%@import namespace="system.data"%>
<%@import namespace="system.data.sqlclient"%>



        上传图片




       
               
               
       
       
               
               
       
       
               
               
       
上传图片
               
               
文件说明
               
               

               
               

               
               



               
//显示图片

<%@page language="c#"%>
<%@import namespace="system.data"%>
<%@import namespace="system.data.sqlclient"%>

热门栏目