Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Problem after uploading a file RSS

3 replies

Last post Jun 11, 2008 04:28 AM by kunal2383

(1)
  • hotdave2

    hotdave2

    Member

    4 Points

    3 Posts

    Problem after uploading a file

    Mar 24, 2008 07:17 PM | LINK


    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 Luo -...

    All-Star

    25149 Points

    2759 Posts

    Microsoft

    Re: Problem after uploading a file

    Mar 26, 2008 06:30 AM | LINK

    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

    4 Points

    3 Posts

    Re: Problem after uploading a file

    Mar 26, 2008 12:50 PM | LINK

    Thanks. It works like a chram.

  • kunal2383

    kunal2383

    Contributor

    5616 Points

    1058 Posts

    Re: Problem after uploading a file

    Jun 11, 2008 04:28 AM | LINK

    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 "Mark As Answer", if this helped you.

    Regards - Kunal Chowdhury | My Blog | Silverlight-Zone