วันอาทิตย์ที่ 8 กุมภาพันธ์ พ.ศ. 2558

javascript: How to upload a file on the click of a button.

<script type="text/javascript">
function loadCommand(btn) {
document.getElementById("fiUpload").click();
}
function AlertFilesize(ClientID) {
if (window.ActiveXObject) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var filepath = ClientID.value;
var thefile = fso.getFile(filepath);
var sizeinbytes = thefile.size;

} else {

var sizeinbytes = ClientID.files[0].size;
}

var fSExt = new Array('Bytes', 'KB', 'MB', 'GB');
fSize = sizeinbytes / 1024; i = 0;

if (Math.round(fSize * 100) / 100 >= 7168) {
ClientID.value = null;
alert("ขนาดเกิน:" + fSize);
}

document.getElementById("btnLoad").innerHTML = '<i class="fa fa-spinner fa-spin fa-lg"></i> Please Wait';
document.getElementById("btnUpload").click();
}
</script>

<asp:FileUpload ID="fiUpload" runat="server" Width="455px"   style ="display:none" onchange="AlertFilesize(this);" />
<asp:LinkButton ID="btnUpload" runat="server"  style ="display:none"   ></asp:LinkButton>                                      
<input id ="btnLoad" type ="button" onclick="loadCommand(this); return;" value ="Upload File" />

************** VB.net ****************
    Protected Sub btnUpload_Click(sender As Object, e As EventArgs) Handles btnUpload.Click
        fiUpload.SaveAs(Server.MapPath(fiUpload.FileName))
    End Sub

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

การใช้ WebClient สำหรับเรียก URL

Dim _url As String = " https :// www . MyDomain . com /?q=ทดสอบ " Dim wc As New System . Net . WebClient () wc . Encodin...