Load Image from Silverlight to ASP.net MVC 2.0 Action

I am having a very hard time loading a photo from a Silverlight application into an ASP.net MVC application.

I am just using WebClient like this in Silverlight:

private bool UploadFile(string fileName, Stream data)
    {
        try
        {
            UriBuilder ub = new UriBuilder("http://localhost:59933/Admin/Upload");
            ub.Query = string.Format("filename={0}", fileName);

            WebClient wc = new WebClient();

            wc.OpenReadCompleted += (sender, e) =>
            {
                PushData(data, e.Result);
                e.Result.Close();
                data.Close();
            };

            wc.OpenWriteAsync(ub.Uri);
        }
        catch (Exception)
        {
            throw;
        }

        return true;
    }


    private void PushData(Stream input, Stream output)
    {
        byte[] buffer = new byte[4096];
        int byteRead;

        while ((byteRead = input.Read(buffer, 0, buffer.Length)) != 0)
        {
            output.Write(buffer, 0, byteRead);
        }

    }

      

On the other hand, I created a simple action called Upload like this:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Upload()
    {
         //Some code here
    }

      

The problem is that it doesn't hit a breakpoint in the load method.

Is it possible? The reason I am using Silverlight is because I want to preview the image before uploading to the server and this is very easy in Silverlight.

I was unable to do this in JavaScript, which is why Silverlight can be more useful.

+2


a source to share





All Articles