locked
save file in ClientBin folder only from Silverlight 4 code RRS feed

  • Question

  • Hi

    I am trying to save a file to ClientBin folder, i know how to do in WCF service  as well as HTTPHandler.

    I too know  that there is no direct access to ClientBin folder , but is there any way i can save file from Silverlight code itself or any other configurationi need to set?

    Please advice...

    Gurpreet 

    Monday, October 24, 2011 3:40 PM

Answers

All replies

  • I think you've answered your own question. Silverlight does not and cannot have write access to the ClientBin folder residing on a public web server. Your only option is to use a web service (such as WCF) which your Silverlight application can call. The web service, since it resides on the web server, should have direct access to the ClientBin directory as long as the file system permissions allow it.

    Monday, October 24, 2011 3:56 PM
  • Totally agree with you Mott sir, but the problem I am facing is I had Byte[] Stream in SL Code, now this I need to save it Client Bin folder as an Image, so that it can be dynamically access by the XAML.

     

    I tried it using WCF service but that is Asynchronous, even I tried to create it as Synchronous, but failed

    http://neverindoubtnet.blogspot.com/2008/07/big-silverlight-troubles-no-synchronous.html

    Please any other idea to do the same …

    Thanks

    Gurpreet 

    Monday, October 24, 2011 4:16 PM
  • I don't see how Async vs. Sync factors into your problem.  You say you have a byte[] that you need to persist on the server.  If you can describe your need in context of your application flow I'm sure that somebody can recommend either a solution or an alternative.

    Monday, October 24, 2011 7:07 PM
  • Let me tell you the Whole story.

    I am creating a Barcode Label Generation Application, which uses a .NET DLL from http://www.codeproject.com/KB/graphics/BarcodeLibrary.aspx

    My aim is to create Bardode from this DLL & put it into Canvas Dynamically.

    This DLL gives me the Image as Byte[] of barcode, which am able to get it in Silverlight using WCF service, now this Byte[] need to save into ClientBin folder as Image so that I can Add this image to my canvas dynamically.

    Now the problem is, the WCF call is ASync, my code for adding the image to Canvas is executed before the WCF call (which returns the Image as Byte[] ). I tried to create the WCF call as Sync. but with no luck

    Thats why i need to store the Image to clientBin folder so that i can add this on the fly.

     

    Hope you understand the requirement....

     

    Thanks

    Gurpreet 

     

     

    Tuesday, October 25, 2011 3:13 AM
  • Based on what you're telling me, it sounds like you could do this with an async call.  I don't know what the exact interface of your service call looks like, but the following code should convey the idea:

    var client = new BarcodeServiceClient();
    client.GetBarcodeCompleted += (sender, args) =>
    {
        if( args.Error != null )
        {
            // going to interact with a control, so ensure we're
            // on the UI thread
            Deployment.Current.Dispatcher.BeginInvoke(
                () =>
                {
                    byte[] imageBytes = args.Result;
                    var imageStream = new MemoryStream(imageBytes);
                    BitmapImage image = new BitmapImage();
                    image.SetSource(imageStream);
                    SomeImageControl.Source = image;
                    imageStream.Close();
                 }
            );
        }
    }
    client.GetBarcodeAsync("FOO");
    Tuesday, October 25, 2011 6:35 AM
  • Hi Gupreet,

    I suspect that there is a better way of doing this. You say you have a barcode image as byte[] from the web server, and want to display this in an image? If so, you don't need to save it to the ClientBin folder on the server, have a look at this thread (http://social.msdn.microsoft.com/Forums/en-US/silverlightcontrols/thread/4c5bd39f-45e3-4198-b689-dd33081271fb#2a545766-2593-4f53-a324-273d1dbd50d5) for help transforming byte arrays into images. Please note that Silverlight only supports PNG or JPEG formats natively - that means if your barcode DLL creates the image in another format such as GIF or BMP, you need to convert it using something like the ImageTools library (http://imagetools.codeplex.com/).

    Regards,
    Rob

    Tuesday, October 25, 2011 6:55 AM