user2256550
user2256550

Reputation: 23

Split file from a url

I had some codes to split files and join ,Now am trying to make a program that split file from a url and download , for example http://tegos.ru/new/mp3_full/David_Guetta_feat_Ne-Yo_and_Akon_-_Play_Hard.mp3 spilit this file in two pieces and download

my split-er code Byte[] byteSource = System.IO.File.ReadAllBytes(FileInputpath); FileInfo fiSource = new FileInfo(txtPath.Text);

        int partsize = (int)Math.Ceiling((double)(fiSource.Length / OutputFiles));

        int fileOffset = 0;
        string currPartPath;
        FileStream fsPart;

        int sizeReamining = (int)fiSource.Length;

        for (int i = 0; i < OutputFiles; i++)
        {
            currPartPath = FolderOutputPath + "\\" + fiSource.Name + "." + String.Format(@"{0:D4}", i) + ".gparts";
            if (!File.Exists(currPartPath))
            {

                fsPart = new FileStream(currPartPath, FileMode.CreateNew);
                sizeReamining = (int)fiSource.Length - (i * partsize);

                if (sizeReamining < partsize)
                {
                    partsize = sizeReamining;
                }
                fsPart.Write(byteSource, fileOffset, partsize);
                fsPart.Close();
                fileOffset += partsize;
            }
        }

Upvotes: 2

Views: 709

Answers (1)

Ruben-J
Ruben-J

Reputation: 2693

Use HttpWebRequest to get a stream from the specified url. When you have the stream, you can use your previous code.

Download/Stream file from URL - asp.net

Upvotes: 1

Related Questions