How to save byte [] as wav file in silverlight application?

In my MVC application, I added Silverlight Audio Recorder. This recorder records audio using System.Windows.Media; namespace as byte[] , which represents a wav file.

Now I need to save this byte[] as a .wav file on the local drive (server).

So far I have tried the following:

 byte[] audioData; // Here I contain my data System.IO.File.WriteAllBytes(@"C:\Temp\yourfile.wav", this.audioData); // Doesn't work BinaryWriter Writer = null; string name = @"C:\Temp\yourfile.wav"; try { Writer = new BinaryWriter(File.OpenWrite(name)); Writer.Write(this.audioData); Writer.Flush(); Writer.Close(); } catch { ... } 

But nothing works for me ... What have I done wrong?

Ok Let's say I can send my data as a json string to the controller:

 WebClient net = new WebClient(); string data = UTF8Encoding.UTF8.GetString(this.audioData, 0, this.audioData.Length); net.UploadStringAsync(new Uri("/Home/SaveFile", UriKind.Relative), data); 

How can I get this data in MVC action?

+1
c # file save silverlight audio
source share
1 answer

Silverlight works on the client side, your MVC code is server-side, so this will not work in the current guise.

I would recommend using a web service to send data to the server in order to save it.

Take a look at WCF or perhaps WebAPI to get up and work with it.

If you really want to make it complex, you can also use something like SignalR to have a client / server (which is essentially what it is configured for) send a connection to each other and send data back through it. Although it seems a bit crowded for this.

0
source share

All Articles