Skip to main content

Microsoft Silverlight

Answered Question Problem after uploading a fileRSS Feed

(1)

hotdave2
hotdave2

Member

Member

4 points

3 Posts

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

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

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.

hotdave2
hotdave2

Member

Member

4 points

3 Posts

Re: Problem after uploading a file

Thanks. It works like a chram.

microsoft_kc
microsof...

Contributor

Contributor

2864 points

561 Posts

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.


Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities