Anthem.NET上传文件

     Anthem.NET可以在此下载:http://sourceforge.net/project/showfiles.php?group_id=151897&package_id=168043&release_id=493609,下载后编译该项目,生成Anthem.dll,在项目中添加Anthem.dll的引用,打开web.config,在configuration>" <system.web>" <pages>" <controls>中添加如下一行,注册Anthem.NET控件:

<add tagPrefix="anthem" namespace="Anthem" assembly="Anthem"/>

Anthem.NET提供了一套自己就带有Ajax功能的、继承于现有ASP.NET控件的服务器端控件。根据上面在web.config文件中的注册,这部分控件的前缀为anthem。

 

< body >
    
< form  id ="form1"  runat ="server" >
        
< fieldset >
            
< legend > Default ASP.NET FileUpload </ legend >
            
< asp:FileUpload  ID ="defaultFileUpload"  runat ="server"   />
            
< asp:Button  ID ="defaultUploadButton"  runat ="server"  OnClick ="defaultUploadButton_Click"  Text ="Upload"   />
            
< asp:Label  ID ="defaultResultLabel"  runat ="server"  Text ="" ></ asp:Label >
        
</ fieldset >
            
        
< fieldset >
            
< legend > Anthem.NET FileUpload </ legend >
            
< anthem:FileUpload  ID ="anthemFileUpload"  runat ="server"   />
            
< anthem:Button  ID ="anthemUploadButton"  TextDuringCallBack ="uploading"  EnabledDuringCallBack ="false"
                runat
="server"  Text ="Upload"  OnClick ="anthemUploadButton_Click"   />
            
< anthem:Label  ID ="anthemResultLabel"  runat ="server"  Text ="" ></ anthem:Label >
        
</ fieldset >
    
</ form >
</ body >

 后台代码:

// 传统方式上传
     protected   void  defaultUploadButton_Click( object  sender, EventArgs e)
    {
        
string  FileName  =  defaultFileUpload.FileName;  // 上传文件名
         int  i  =  FileName.LastIndexOf( " . " );
        
string  FileEx  =  FileName.Substring(i);  // 文件扩展名.jpg
         string  SaveFileName  =   string .Format( " default{0}{1}{2}{3} " ,DateTime.Now.ToShortDateString(),DateTime.Now.Millisecond.ToString(),defaultFileUpload.FileBytes.Length.ToString() , FileEx);
        defaultFileUpload.PostedFile.SaveAs(Server.MapPath(
" upload\\ "   +  SaveFileName));
        defaultResultLabel.Text 
=   string .Format( " File \ " { 0 }\ "  uploaded ({1} bytes,{2}). " ,
            defaultFileUpload.FileName,
            defaultFileUpload.FileBytes.Length,
            SaveFileName
        );
    }
    
// anthem方式上传
     protected   void  anthemUploadButton_Click( object  sender, EventArgs e)
    {
        
string  FileName  =  anthemFileUpload.FileName;
        
int  i  =  FileName.LastIndexOf( " . " );
        
string  FileEx  =  FileName.Substring(i);
        
string  SaveFileName  =   string .Format( " anthem{0}{1}{2}{3} " , DateTime.Now.ToShortDateString(), DateTime.Now.Millisecond.ToString(), anthemFileUpload.FileBytes.Length.ToString(), FileEx);
        anthemFileUpload.PostedFile.SaveAs(Server.MapPath(
" upload\\ " + SaveFileName));
        anthemResultLabel.Text 
=   string .Format( " File \ " { 0 }\ "  uploaded ({1} bytes,{2}). " ,
            anthemFileUpload.FileName,
            anthemFileUpload.FileBytes.Length,
            SaveFileName
        );
        anthemResultLabel.UpdateAfterCallBack 
=   true ;
    }

 

你可能感兴趣的:(.net)