Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Problem after uploading a file
3 replies. Latest Post by microsoft_kc on June 11, 2008.
(1)
hotdave2
Member
4 points
3 Posts
03-24-2008 3:17 PM |
void btnSave_Click(object sender, RoutedEventArgs e) {try{btnSave.Visibility = Visibility.Collapsed; btnCancel.Visibility = Visibility.Collapsed;formBody = "Function=SaveDesign&" + "fileName=" + txtName.Text + ".SVG" + "&" +"fileContents=" + Content; //starts uploading processWebRequest request = (WebRequest)HttpWebRequest.Create(new Uri("http://localhost:2721/TestEnvir_Web/DesignServices.ashx")); request.Method = "POST";request.ContentType = "application/x-www-form-urlencoded"; request.BeginGetRequestStream(new AsyncCallback(ReadyToUpload), request);request.BeginGetResponse(new AsyncCallback(DoneUploading), request); }catch (Exception ex) {}}void ReadyToUpload(IAsyncResult sender) {try{WebRequest request = (WebRequest)sender.AsyncState;StreamWriter sw = new StreamWriter(request.EndGetRequestStream(sender)); sw.Write(formBody);sw.Flush();sw.Close();}catch (Exception ex) {}}void DoneUploading(IAsyncResult sender) {try{string temp;WebRequest request = sender.AsyncState as WebRequest; Stream responseStream = request.EndGetResponse(sender).GetResponseStream();StreamReader reader = new StreamReader(responseStream); temp = reader.ReadToEnd();fce.cancel = false;Completed(this, fce); }catch (Exception ex) {}}
after all this code is executed it throw "Error HRESULT E_FAIL has been returned from a call to a COM component" stack trace :
at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData) at System.Windows.DependencyObject.MethodEx(String methodName, CValue[] cvData) at System.Windows.UIElement.ReleaseMouseCapture() at System.Windows.Controls.Primitives.ButtonBase.ReleaseMouseCaptureInternal() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(Object sender, MouseButtonEventArgs e) at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
the file gets saved and email just fine. However, the page has to been refleshed to be used again
Yi-Lun L...
All-Star
25052 points
2,747 Posts
03-26-2008 2:30 AM |
Hello, this is a known issue. In MouseLeftButtonUp event handler of Button, it'll first fire Click event (thus call your own handler), and then release mouse capture. But since you've hidden you Button, the ReleaseMouseCaptureInternal method will throw an Exception. I think what you want is to disable the Button to prevent the user upload the file again. So can you set IsEnabled to false instead? If you really want to hide the Button, you can set its size to 0.
03-26-2008 8:50 AM |
Thanks. It works like a chram.
microsof...
Contributor
2864 points
561 Posts
06-11-2008 12:28 AM |
You can use the following:
private void btnClick_Click(object sender, RoutedEventArgs e)
{
// what we generally do: btnClick.Visibility = Visibility.Collapsed;
// instead of doing the general coding, do this:
Dispatcher.BeginInvoke(() => { btnClick.Visibility = Visibility.Collapsed; });
}
hotdave2: void btnSave_Click(object sender, RoutedEventArgs e) {try{btnSave.Visibility = Visibility.Collapsed; btnCancel.Visibility = Visibility.Collapsed;formBody = "Function=SaveDesign&" + "fileName=" + txtName.Text + ".SVG" + "&" +"fileContents=" + Content; //starts uploading processWebRequest request = (WebRequest)HttpWebRequest.Create(new Uri("http://localhost:2721/TestEnvir_Web/DesignServices.ashx")); request.Method = "POST";request.ContentType = "application/x-www-form-urlencoded"; request.BeginGetRequestStream(new AsyncCallback(ReadyToUpload), request);request.BeginGetResponse(new AsyncCallback(DoneUploading), request); }catch (Exception ex) {}}void ReadyToUpload(IAsyncResult sender) {try{WebRequest request = (WebRequest)sender.AsyncState;StreamWriter sw = new StreamWriter(request.EndGetRequestStream(sender)); sw.Write(formBody);sw.Flush();sw.Close();}catch (Exception ex) {}}void DoneUploading(IAsyncResult sender) {try{string temp;WebRequest request = sender.AsyncState as WebRequest; Stream responseStream = request.EndGetResponse(sender).GetResponseStream();StreamReader reader = new StreamReader(responseStream); temp = reader.ReadToEnd();fce.cancel = false;Completed(this, fce); }catch (Exception ex) {}} after all this code is executed it throw "Error HRESULT E_FAIL has been returned from a call to a COM component" stack trace : at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData) at System.Windows.DependencyObject.MethodEx(String methodName, CValue[] cvData) at System.Windows.UIElement.ReleaseMouseCapture() at System.Windows.Controls.Primitives.ButtonBase.ReleaseMouseCaptureInternal() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(Object sender, MouseButtonEventArgs e) at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName) the file gets saved and email just fine. However, the page has to been refleshed to be used again