說起來之前一直看不起Silverlight,因為MS的Selas整天只會說清明上河圖
SL 4.0出來感覺滿有劃世代的感覺呢 !
0.宣告物件
public FileInfo File1.觸發
{
get { return _file; }
set
{
_file = value;
Stream temp = _file.OpenRead();
FileLength = temp.Length;
temp.Close();
BytesUploaded = 0;
}
}
拉一個image物件,然後設定其
Allow drop = trueDrop事件:
private void image1_Drop(object sender, DragEventArgs e)2.取得檔案
{
IDataObject dataObject = e.Data;
FileInfo[] fileInfoArray = dataObject.GetData("FileDrop") as FileInfo[];
e.Handled = true;
}
private void SendNextFile()3.將資料post到Server
{
if (_listFiles.Count > 0)
{
File = _listFiles[0];
//檔案大小檢查
long fz = Convert.ToInt32(file_Size) * 1024 * 1024;
if (fz > 0) ChunkSize = fz;
if (File.Length > fz) { MessageBox.Show("檔案大小限制:" + file_Size "MB"); return; }
//上傳
UploadFileEx();
}
private void UploadFileEx()4.利用委派的方式更新進度列
{
long temp = FileLength - BytesUploaded;
string ubi = HOST_URL + "/" + ASHX_URL; //處理檔案的對應泛型處理常式
UriBuilder ub = new UriBuilder(ubi);
string new_id = Guid.NewGuid().ToString();
ub.Query = string.Format("{4}filename={0}&StartByte={1}&Complete={2}&newid={3}", File.Name, BytesUploaded, complete, new_id, string.IsNullOrEmpty(ub.Query) ? "" : ub.Query.Remove(0, 1) + "&");
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ub.Uri);
webrequest.Method = "POST";
IAsyncResult ia = webrequest.BeginGetRequestStream(new AsyncCallback(WriteCallback), webrequest);
if (ia.IsCompleted) SetLabelObj();
}
public delegate void UpdateUICallBack();
private void UpdataPrg(long uped)
{
lbl_bytes.Content = uped.ToString() + " / " + FileLength.ToString();
}
public void UpdataUICompile()
{
}
參數的傳入:利用"InitParams"傳入參數
<param name="InitParams" value="fileSize=4, ... >結果的輸出:利用Silverlight調用Javascript
HtmlPage.Window.Invoke("RunEndScript", v);
--
能夠填平大海的誓言,也比不上邁出一步的價值
是以吾輩此生,再無任何誓言
沒有留言:
張貼留言