Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save byte[] as assembly? 1

Status
Not open for further replies.

litton1

Technical User
Apr 21, 2005
584
GB
Hi all,
I have a web service that returns a byte[] which should be an application. My question is, how in the client do I now save that byte array back to the local file system as an assembly (could be an exe or dll if this matters)?

Age is a consequence of experience
 
solved! Simple...
Code:
System.IO.File.WriteAllBytes( newPath, myAppArray );

Age is a consequence of experience
 
This is how i would go about it.

Code:
try
            {
                request = (HttpWebRequest)WebRequest.Create(uri);
                request.Timeout = 10000;
                request.AllowWriteStreamBuffering = false;
                response = (HttpWebResponse)request.GetResponse();

                Stream s = response.GetResponseStream();
                //Write to disk
                FileStream fs = new FileStream(my_file_path, FileMode.Create);
                byte[] read = new byte[256];
                int count = s.Read(read, 0, read.Length);

                while (count > 0)
                {
                    fs.Write(read, 0, count);
                    count = s.Read(read, 0, read.Length);
                }
                //Close everything
                fs.Close();
                s.Close();
                response.Close();
            }
            catch (System.Net.WebException)
            {
                if (response != null)
                    response.Close();
                
            }
 
I agree.. Nice thanks, have a star!

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top