• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1123
  • Last Modified:

Convert a Stream Object to File Stream In Silverlight

i am getting an audio file from server in silver light application. I am getting stream in a Stream object. I need to convert this is into "filestream". Is there is any solution to do this. Please help me out.

Here is the code.

string UrlString = SongURL
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(UrlString));
request.BeginGetResponse(new AsyncCallback(ReadCallback), request);

 private void ReadCallback(IAsyncResult asynchronousResult)
        {
            this.Dispatcher.BeginInvoke(delegate()
            {
                HttpWebRequest request =
                              (HttpWebRequest)asynchronousResult.AsyncState;
                HttpWebResponse response =
                  (HttpWebResponse)request.EndGetResponse(asynchronousResult);
                //using (StreamReader streamReader1 =
                //  new StreamReader(response.GetResponseStream()))
                //{
                //    string resultString = streamReader1.ReadToEnd();
                //   // resultBlock.Text = "Using HttpWebRequest: " + resultString;
                //}
                Stream streamReader1 = response.GetResponseStream();
 }


0
Ajit_Kr
Asked:
Ajit_Kr
  • 2
  • 2
2 Solutions
 
CuteBugCommented:
There are two ways to achieve that
1.
byte[] data = stream.ToArray();
File.WriteAllBytes(newFile, data);

2.
using (FileStream fs = File.Create(newFile))
{
    stream.WriteTo(fs);
}

Check this link
http://stackoverflow.com/questions/555799/convert-memorystream-to-filestream-creates-hundreds-of-identical-files
0
 
Ajit_KrAuthor Commented:
File.WriteAllBytes(newFile, data);
In silverlight file class doesn't have WriteAllBytes() method..
Please suggest more.

0
 
CuteBugCommented:
You can write to an IsolatedStorageFile.

Check this link

http://forums.silverlight.net/forums/p/22011/77243.aspx
0
 
Ajit_KrAuthor Commented:
ss
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now