当前位置: 移动技术网 > IT编程>开发语言>.net > 上传

上传

2018年10月11日  | 移动技术网IT编程  | 我要评论

邢台五中贴吧,仲维军,老庄钱

1、asp 的上传

 <ext:pagemanager id="pagemanager1" runat="server" enableajax="false" />
  <asp:fileupload id="fileupload1" runat="server"></asp:fileupload>
 <asp:button id="btnclosewindow2" runat="server" text="上传文件" onclick="btnclosewindow2_click"></asp:button>
 
   protected void btnclosewindow2_click(object sender, eventargs e)
  {
      if (fileupload1.hasfile)
     {
         fileupload1.saveas(server.mappath("~/upload/" + fileupload1.filename));
     }
      alert.showintop("文件上传成功!");
  }

有两个突出问题:1. 文件上传框风格和整个页面风格不搭配。 2. 上传时是整个页面回发,和fineui默认的ajax风格也不搭。

2、fineui 的上传

<ext:simpleform id="simpleform1" bodypadding="5px" runat="server" enablebackgroundcolor="true"
     showborder="true" title="表单" width="350px" showheader="true">
    <items>
       <ext:textbox runat="server" label="用户名" id="tbxuseraname" required="true" showredstar="true">
         </ext:textbox>
          <ext:fileupload runat="server" id="filephoto" emptytext="请选择一张照片" label="个人头像" required="true"
             showredstar="true">
         </ext:fileupload>
         <ext:button id="btnsubmit" runat="server" onclick="btnsubmit_click" validateforms="simpleform1"
              text="提交">
           </ext:button>
      </items>
   </ext:simpleform>
 
  protected void btnsubmit_click(object sender, eventargs e)
  {
       string filename = datetime.now.ticks.tostring() + "_" + filephoto.filename;
    if (filephoto.hasfile)
       {
           filephoto.saveas(server.mappath("~/upload/" + filename));
       }

下面来看看fileupload的属性:

  1. buttontext:按钮文本。
  2. buttononly:是否只显示按钮,不显示只读输入框。
  3. buttonicon:按钮图标。
  4. buttoniconurl:按钮图标地址。
  5. postedfile:上传的文件。
  6. hasfile:是否包含文件。
  7. filename:上传文件名。

还有一个重要的方法 saveas,用来将上传的文本保存到服务器上

3、实例

<f:fileupload id="selectfile" runat="server"  label="更新文件"  ></f:fileupload>

string uploadfilepath = server.mappath("~/app/");
        //完整路径名称
        string fullfilename = uploadfilepath + selectfile.filename;

 if (system.io.file.exists(fullfilename)) 
            {
                system.io.file.delete(fullfilename);
            }

            selectfile.saveas(fullfilename);

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网