Goodspeed

导航

Gmail式的上传

原理参见
http://www.cnblogs.com/xbf321/archive/2007/11/09/954317.html

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title>File Upload</title>
    
<script type="text/javascript" src="js/jquery-1.2.6.js"></script>
    
<script type="text/javascript">
    $(document).ready(
function(){
        
if(window.top == window)
        {
            
var $div = $(document.createElement("div"));
            $div.html(
"<iframe src='"+document.URL+"' name='uploadiframe' id='uploadiframe'></iframe>");
            $div.css({display:
"none"})
            $(
"body").append($div);
            $(
"form").attr("target","uploadiframe");
            $(
"form").submit();
            
            
            $(
".myupload").empty(); 
            
var $a = $(document.createElement("a"));
            $($a).html(
"upload");
            
            
            $($a).click(
function(){
                $(
"#uploadiframe").contents().find(":file").click();
                $(
"#uploadiframe").contents().find(":submit").click();
                
return false;
            });
            
            $(
".myupload").append($a); 
        }
    });
    
</script>
    
<script type="text/C#" runat="server">
        protected 
void File_Upload(object sender, EventArgs e)
        {
            
if (FileUploadControl.HasFile == true)
            {
                FileUploadControl.SaveAs(@
"D:\upload\" + FileUploadControl.FileName);
            }
        }
    
</script>
</head>
<body>
    
<form id="form1" runat="server">
    
<div class="myupload">
    
<asp:FileUpload ID="FileUploadControl" runat="server" />
    
<asp:Button runat="server" OnClick="File_Upload" Text="Upload It" />
    
</div>
    
</form>
</body>
</html>


 

posted on 2008-08-01 10:58  Goodspeed  阅读(652)  评论(0编辑  收藏  举报