/// <summary>takes our copy of the stream, and puts it into the request stream</summary> protected void CopyRequestData() { if (_requestCopy != null) { // Since we don't use write buffering on the WebRequest object, // we need to ensure the Content-Length field is correctly set // to the length we want to set. EnsureWebRequest(); Request.ContentLength = _requestCopy.Length; // stream it into the real request stream Stream req = base.GetRequestStream(); try { const int size = 4096; byte[] bytes = new byte[size]; int numBytes; double oneLoop = 100; if (_requestCopy.Length > size) { oneLoop = (100 / ((double)_requestCopy.Length / size)); } // 3 lines of debug code // this.requestCopy.Seek(0, SeekOrigin.Begin); // StreamReader reader = new StreamReader( this.requestCopy ); // string text = reader.ReadToEnd(); _requestCopy.Seek(0, SeekOrigin.Begin); long bytesWritten = 0; double current = 0; while ((numBytes = _requestCopy.Read(bytes, 0, size)) > 0) { req.Write(bytes, 0, numBytes); bytesWritten += numBytes; if (_asyncData != null && _asyncData.Delegate != null && _asyncData.DataHandler != null) { AsyncOperationProgressEventArgs args; args = new AsyncOperationProgressEventArgs( _requestCopy.Length, bytesWritten, (int)current, Request.RequestUri, Request.Method, _asyncData.UserData); current += oneLoop; if (!_asyncData.DataHandler.SendProgressData(_asyncData, args)) { break; } } } } finally { req.Close(); } } else { if (IsBatch) { EnsureWebRequest(); ContentStore.SaveToXml(GetRequestStream()); CopyRequestData(); } } }