Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. saving a remote binary file (swf) locally with c#

saving a remote binary file (swf) locally with c#

Scheduled Pinned Locked Moved C#
csharpphpcomadobedebugging
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sascho
    wrote on last edited by
    #1

    Hi there! I am trying to save different .swf files on my local machine. Actually this is already working with the below code. Unfortunately (how I already figured while writing the code) The file is saved, but somehow corrupted. Is there maybe a way more simple way to get the Response of an URI into a string (or, let's say a buffer) and save it on my disk? Below is the code I came up with (within a C# web application): // init bool debug = false; // this is where I get my test-swf, you can have a look at it at: // http://www.styte.com/3.swf // it may look strange, what I am trying to do is to read some php-created // swf's into my .net application.... string url = "http://www.styte.com/trans.php?&bild=3.swf"; // work Uri fileUrl = new Uri(url); // Create 'FileWebrequest' object with specified Uri. WebRequest myFileWebRequest = (WebRequest)WebRequest.Create(fileUrl); // Send 'FileWebRequest' object & wait for response. WebResponse myFileWebResponse = (WebResponse)myFileWebRequest.GetResponse(); // Get stream object associated with response object. Stream receiveStream = myFileWebResponse.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("windows-1252"); //("utf-8"); // Pipe stream to higher level stream reader with req. encoding format. StreamReader readStream = new StreamReader (receiveStream, encode); if (debug==true) Response.Write("\r\nResponse stream received
    "); int numChars = 1; Char[] read = new Char[numChars]; // Read "numChars" characters at a time. int count = readStream.Read ( read, 0, numChars ); if (debug==true) Response.Write("(count): "+count.ToString()+" File Data...\r\n"); //Response.ContentType = "application/x-shockwave-flash"; //Response.AddHeader("Content-Type", "application/x-shockwave-flash"); FileStream fs = File.Create(@"C:\Inetpub\wwwroot\leilac\uploads\test.swf"); BinaryWriter bw = new BinaryWriter(fs); while (count > 0) { String str = new String(read, 0, count); bw.Write(str); Response.Write(str); count = readStream.Read(read, 0, numChars); } bw.Close(); fs.Close(); if (debug==true) Response.Write("
    "); // Release resources of stream & response object. readStream.Close(); myFileWebResponse.Close(); Response.End(); Appreciate any comments/help. Sasch, styte, http://www.styte.com/

    G D J 3 Replies Last reply
    0
    • S sascho

      Hi there! I am trying to save different .swf files on my local machine. Actually this is already working with the below code. Unfortunately (how I already figured while writing the code) The file is saved, but somehow corrupted. Is there maybe a way more simple way to get the Response of an URI into a string (or, let's say a buffer) and save it on my disk? Below is the code I came up with (within a C# web application): // init bool debug = false; // this is where I get my test-swf, you can have a look at it at: // http://www.styte.com/3.swf // it may look strange, what I am trying to do is to read some php-created // swf's into my .net application.... string url = "http://www.styte.com/trans.php?&bild=3.swf"; // work Uri fileUrl = new Uri(url); // Create 'FileWebrequest' object with specified Uri. WebRequest myFileWebRequest = (WebRequest)WebRequest.Create(fileUrl); // Send 'FileWebRequest' object & wait for response. WebResponse myFileWebResponse = (WebResponse)myFileWebRequest.GetResponse(); // Get stream object associated with response object. Stream receiveStream = myFileWebResponse.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("windows-1252"); //("utf-8"); // Pipe stream to higher level stream reader with req. encoding format. StreamReader readStream = new StreamReader (receiveStream, encode); if (debug==true) Response.Write("\r\nResponse stream received
      "); int numChars = 1; Char[] read = new Char[numChars]; // Read "numChars" characters at a time. int count = readStream.Read ( read, 0, numChars ); if (debug==true) Response.Write("(count): "+count.ToString()+" File Data...\r\n"); //Response.ContentType = "application/x-shockwave-flash"; //Response.AddHeader("Content-Type", "application/x-shockwave-flash"); FileStream fs = File.Create(@"C:\Inetpub\wwwroot\leilac\uploads\test.swf"); BinaryWriter bw = new BinaryWriter(fs); while (count > 0) { String str = new String(read, 0, count); bw.Write(str); Response.Write(str); count = readStream.Read(read, 0, numChars); } bw.Close(); fs.Close(); if (debug==true) Response.Write("
      "); // Release resources of stream & response object. readStream.Close(); myFileWebResponse.Close(); Response.End(); Appreciate any comments/help. Sasch, styte, http://www.styte.com/

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      I believe that you should skip the encoding. --- b { font-weight: normal; }

      S 1 Reply Last reply
      0
      • G Guffa

        I believe that you should skip the encoding. --- b { font-weight: normal; }

        S Offline
        S Offline
        sascho
        wrote on last edited by
        #3

        Hey Guffa! Hmmm, I was thinking about that from the beginning, but how to do so? S.

        1 Reply Last reply
        0
        • S sascho

          Hi there! I am trying to save different .swf files on my local machine. Actually this is already working with the below code. Unfortunately (how I already figured while writing the code) The file is saved, but somehow corrupted. Is there maybe a way more simple way to get the Response of an URI into a string (or, let's say a buffer) and save it on my disk? Below is the code I came up with (within a C# web application): // init bool debug = false; // this is where I get my test-swf, you can have a look at it at: // http://www.styte.com/3.swf // it may look strange, what I am trying to do is to read some php-created // swf's into my .net application.... string url = "http://www.styte.com/trans.php?&bild=3.swf"; // work Uri fileUrl = new Uri(url); // Create 'FileWebrequest' object with specified Uri. WebRequest myFileWebRequest = (WebRequest)WebRequest.Create(fileUrl); // Send 'FileWebRequest' object & wait for response. WebResponse myFileWebResponse = (WebResponse)myFileWebRequest.GetResponse(); // Get stream object associated with response object. Stream receiveStream = myFileWebResponse.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("windows-1252"); //("utf-8"); // Pipe stream to higher level stream reader with req. encoding format. StreamReader readStream = new StreamReader (receiveStream, encode); if (debug==true) Response.Write("\r\nResponse stream received
          "); int numChars = 1; Char[] read = new Char[numChars]; // Read "numChars" characters at a time. int count = readStream.Read ( read, 0, numChars ); if (debug==true) Response.Write("(count): "+count.ToString()+" File Data...\r\n"); //Response.ContentType = "application/x-shockwave-flash"; //Response.AddHeader("Content-Type", "application/x-shockwave-flash"); FileStream fs = File.Create(@"C:\Inetpub\wwwroot\leilac\uploads\test.swf"); BinaryWriter bw = new BinaryWriter(fs); while (count > 0) { String str = new String(read, 0, count); bw.Write(str); Response.Write(str); count = readStream.Read(read, 0, numChars); } bw.Close(); fs.Close(); if (debug==true) Response.Write("
          "); // Release resources of stream & response object. readStream.Close(); myFileWebResponse.Close(); Response.End(); Appreciate any comments/help. Sasch, styte, http://www.styte.com/

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          sascho wrote: Encoding encode = System.Text.Encoding.GetEncoding("windows-1252"); //("utf-8"); // Pipe stream to higher level stream reader with req. encoding format. StreamReader readStream = new StreamReader (receiveStream, encode); if (debug==true) Response.Write("\r\nResponse stream received "); Instead of using a StreamReader, have you tried using a BinaryReader[^]? You don't have to specify an Encoding with it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          • S sascho

            Hi there! I am trying to save different .swf files on my local machine. Actually this is already working with the below code. Unfortunately (how I already figured while writing the code) The file is saved, but somehow corrupted. Is there maybe a way more simple way to get the Response of an URI into a string (or, let's say a buffer) and save it on my disk? Below is the code I came up with (within a C# web application): // init bool debug = false; // this is where I get my test-swf, you can have a look at it at: // http://www.styte.com/3.swf // it may look strange, what I am trying to do is to read some php-created // swf's into my .net application.... string url = "http://www.styte.com/trans.php?&bild=3.swf"; // work Uri fileUrl = new Uri(url); // Create 'FileWebrequest' object with specified Uri. WebRequest myFileWebRequest = (WebRequest)WebRequest.Create(fileUrl); // Send 'FileWebRequest' object & wait for response. WebResponse myFileWebResponse = (WebResponse)myFileWebRequest.GetResponse(); // Get stream object associated with response object. Stream receiveStream = myFileWebResponse.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("windows-1252"); //("utf-8"); // Pipe stream to higher level stream reader with req. encoding format. StreamReader readStream = new StreamReader (receiveStream, encode); if (debug==true) Response.Write("\r\nResponse stream received
            "); int numChars = 1; Char[] read = new Char[numChars]; // Read "numChars" characters at a time. int count = readStream.Read ( read, 0, numChars ); if (debug==true) Response.Write("(count): "+count.ToString()+" File Data...\r\n"); //Response.ContentType = "application/x-shockwave-flash"; //Response.AddHeader("Content-Type", "application/x-shockwave-flash"); FileStream fs = File.Create(@"C:\Inetpub\wwwroot\leilac\uploads\test.swf"); BinaryWriter bw = new BinaryWriter(fs); while (count > 0) { String str = new String(read, 0, count); bw.Write(str); Response.Write(str); count = readStream.Read(read, 0, numChars); } bw.Close(); fs.Close(); if (debug==true) Response.Write("
            "); // Release resources of stream & response object. readStream.Close(); myFileWebResponse.Close(); Response.End(); Appreciate any comments/help. Sasch, styte, http://www.styte.com/

            J Offline
            J Offline
            jkersch
            wrote on last edited by
            #5

            You could also try the following (very simple) code: System.Net.WebClient wc = new System.Net.WebClient(); wc.DownloadFile(URIString,FileNameString); maybe this is not that complicated for such a trivial task. best regards jkersch

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups