Problem with multiple file upload control


hi all,

        have silverlight file upload control embeeded in webform. problem when try upload making postback save data on page making postback before file upload control uploads images. need postback after file upload control finishes upload. how can provide time delay?

thanks

rishi

ok no problem use code file uploading , return message box uploded on ok click page postback, please handle dialog result well.

sample code:

using system; using system.collections.generic; using system.io; using system.linq; using system.net; using system.text; using system.threading; using system.windows; using system.windows.controls; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.animation; using system.windows.shapes; using system.xml;  namespace simplefileupload {     public partial class mainpage : usercontrol     {          /// <summary>         /// chunk size in bytes: file uploaded in blocks of these. smaller thet size, more accurate upload progress bar , more requests there made webserver         /// </summary>         public const int chunk_size = 1024;         /// <summary>         /// uri thet upload made         /// set either <yourhost>/fileupload.ashx?filename={0}&append={1} or <yourhost>/fileupload.php?filename={0}&append={1}         /// </summary>          public const string upload_uri_n = "http://192.168.10.248/vdmscripts/vdmisapidisp.dll/soap/rfc/logon?cmd=nothing&nosoap=1&filename={0}&o={1}&bs={2}&s={3}";         public const string upload_uri_a = "http://192.168.10.248/vdmscripts/vdmisapidisp.dll/soap/rfc/logon?cmd=nothing&nosoap=1&filename={0}&o={1}";          /// <summary>         /// filter file upload dialog         /// </summary>         public const string upload_dialog_filter = "all files (*.*)|*.*|jpeg images (*.jpg)|*.png|png images (*.png)|*.png";          private stream _data;         private string _filename;         private long _bytestotal;         private long _bytesuploaded;         private bool cancel = false;         private string log;         private string logheader;         public webheadercollection headers;          public mainpage()         {             initializecomponent();         }          private void upload_click(object sender, routedeventargs e)         {             openfiledialog dlg = new openfiledialog();             dlg.multiselect = false;             dlg.filter = upload_dialog_filter;             bool? retval = dlg.showdialog();              if (retval != null && retval==true)             {                 progressbar.visibility = visibility.visible;                 textbox.visibility = visibility.visible;                 textbox.text = "upload starting...";                  _data = dlg.file.openread();                 _bytestotal = _data.length;                 _bytesuploaded = 0;                 _filename = dlg.file.name;                 progressbar.maximum = _bytestotal;                  uploadfilechunk();               }         }          private void uploadfilechunk()         {              textbox.text = "upload in progress..." + _bytesuploaded + " / " + _bytestotal;             string uploaduri = "";              if (_bytesuploaded == 0)             {                 uploaduri = string.format(upload_uri_n, _filename, 0, chunk_size, _bytestotal); // dont't append             }             else if (_bytesuploaded < _bytestotal && !cancel)             {                 uploaduri = string.format(upload_uri_a, _filename, _bytesuploaded); // append             }             else             {                 return;  // upload finished                             }              if (_bytesuploaded > 3000)             {                 uploaduri = string.format(upload_uri_a+"&xyz=1", _filename, _bytesuploaded); // append             }              byte[] filecontent = new byte[chunk_size];             int bytesread = _data.read(filecontent, 0, chunk_size);             _data.flush();              webclient wc = new webclient();              wc.openwritecompleted += new openwritecompletedeventhandler(wc_openwritecompleted);             uri u = new uri(uploaduri);             wc.openwriteasync(u, null, new object[] { filecontent, bytesread });             _bytesuploaded += filecontent.length;                           // here goes nothing, can't              headers = wc.responseheaders;             logheader = "header:";             (int = 0; < headers.count; i++)             {                 logheader = headers.allkeys.getvalue(0).tostring();             }          }          void wc_openwritecompleted(object sender, openwritecompletedeventargs e)         {              progressbar.value = _bytesuploaded;             if (e.error == null)             {                 object[] objarr = e.userstate object[];                 byte[] filecontent = objarr[0] byte[];                 int bytesread = convert.toint32(objarr[1]);                 stream outputstream = e.result;                 outputstream.write(filecontent, 0, bytesread);                 outputstream.close();                  float turnsmax = _bytestotal / chunk_size;                  if (_bytesuploaded < _bytestotal)                 {                     uploadfilechunk();                 }                 else                 {                     textbox.text = "upload complete!";                     messagebox.show("response " + logheader);                 }              }             else             {                 messagebox.show("error");             }                      }          private void image1_imagefailed(object sender, exceptionroutedeventargs e)         {          }      } }


Silverlight  >  Getting Started with Silverlight



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........