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
  1. Home
  2. General Programming
  3. C#
  4. Upload Large Audio File

Upload Large Audio File

Scheduled Pinned Locked Moved C#
question
5 Posts 2 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
    sjs4u
    wrote on last edited by
    #1

    Hi, I am uploading large audio file using webclient in windows form. Now if file is small then it is uploading but if file is larger in size like 200 mb or more then it showing exception that System.OutOfMemoryException . So How can I solved it. My code is give below. WebClient client = new WebClient(); Stream stream = client.OpenWrite(remoteFilename, "PUT"); // The buffer size is set to 2kb const int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; // Opens a file stream (System.IO.FileStream) to read the file // to be uploaded FileStream fs = fileInf.OpenRead(); int doneSoFar = 0; // Read from the file stream 2kb at a time contentLen = fs.Read(buff, 0, buffLength); //added for accurate progress doneSoFar += contentLen; setItemStatus("Uploading"); while (contentLen != 0) { setItemProgress(doneSoFar, fileInf.Length); // Write Content from the file stream to the FTP Upload Stream stream.Write(buff, 0, contentLen); contentLen = fs.Read(buff, 0, buffLength); doneSoFar += contentLen; } // Close the file stream and the Request Stream stream.Close(); fs.Close(); Thanks sjs

    M 1 Reply Last reply
    0
    • S sjs4u

      Hi, I am uploading large audio file using webclient in windows form. Now if file is small then it is uploading but if file is larger in size like 200 mb or more then it showing exception that System.OutOfMemoryException . So How can I solved it. My code is give below. WebClient client = new WebClient(); Stream stream = client.OpenWrite(remoteFilename, "PUT"); // The buffer size is set to 2kb const int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; // Opens a file stream (System.IO.FileStream) to read the file // to be uploaded FileStream fs = fileInf.OpenRead(); int doneSoFar = 0; // Read from the file stream 2kb at a time contentLen = fs.Read(buff, 0, buffLength); //added for accurate progress doneSoFar += contentLen; setItemStatus("Uploading"); while (contentLen != 0) { setItemProgress(doneSoFar, fileInf.Length); // Write Content from the file stream to the FTP Upload Stream stream.Write(buff, 0, contentLen); contentLen = fs.Read(buff, 0, buffLength); doneSoFar += contentLen; } // Close the file stream and the Request Stream stream.Close(); fs.Close(); Thanks sjs

      M Offline
      M Offline
      MumbleB
      wrote on last edited by
      #2

      Are you running this in a Thread?

      Excellence is doing ordinary things extraordinarily well.

      S 1 Reply Last reply
      0
      • M MumbleB

        Are you running this in a Thread?

        Excellence is doing ordinary things extraordinarily well.

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

        Hi Thanks for reply.. I am not using any thread. Can you pls show me how can i write thread in the above mention code Thanks Sjs

        modified on Saturday, March 6, 2010 5:03 AM

        M 1 Reply Last reply
        0
        • S sjs4u

          Hi Thanks for reply.. I am not using any thread. Can you pls show me how can i write thread in the above mention code Thanks Sjs

          modified on Saturday, March 6, 2010 5:03 AM

          M Offline
          M Offline
          MumbleB
          wrote on last edited by
          #4

          It is pretty simple though. Make sure you add

          using System.Threading;

          private void btn_StartLoad_Click(object sender, EventArgs e) { ThreadStart startload = new ThreadStart(startUpload); Thread threadload = new Thread(startload); threadload.Start(); } private void startUpload() { //Put your code here }

          Excellence is doing ordinary things extraordinarily well.

          S 1 Reply Last reply
          0
          • M MumbleB

            It is pretty simple though. Make sure you add

            using System.Threading;

            private void btn_StartLoad_Click(object sender, EventArgs e) { ThreadStart startload = new ThreadStart(startUpload); Thread threadload = new Thread(startload); threadload.Start(); } private void startUpload() { //Put your code here }

            Excellence is doing ordinary things extraordinarily well.

            S Offline
            S Offline
            sjs4u
            wrote on last edited by
            #5

            ok Thanks I will check it out

            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