Page view counter
Problem after uploading a file Subscribe to this thread
Last post 06-11-2008 12:28 AM by microsoft_kc. 3 replies.
Sort Posts:
03-24-2008 3:17 PM
Problem after uploading a file


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 process
WebRequest 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

hotdave2

Loading...
Joined on 03-24-2008
Posts 3
03-26-2008 2:30 AM
Marked as Answer
Re: Problem after uploading a file

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.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Yi-Lun Luo - MSFT

Loading...
Joined on 10-29-2007
Posts 2,747
03-26-2008 8:50 AM
Re: Problem after uploading a file

Thanks. It works like a chram.

hotdave2

Loading...
Joined on 03-24-2008
Posts 3
06-11-2008 12:28 AM
Re: Problem after uploading a file

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 process
WebRequest 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

Remember: Please click on "Mark As Answer", if this answered your query partially or fully.

Thanks & Regards,
Kunal (My Blog)

microsoft_kc

Loading...
Joined on 03-27-2008
Pune, India
Posts 474
Microsoft Communities