Skip to main content

Download a file from a document library

You can download a file from a file stream quickly by passing in a SPFile object and the path where you want it to be written to:


static void DownloadFileUsingFileStream(SPFile file, string path)
        {
            byte[] filecontent = file.OpenBinary();
            FileStream fs = new FileStream(path + file.Name, FileMode.CreateNew);
            using (fs)
            {
                BinaryWriter bw = new BinaryWriter(fs);
                bw.Write(filecontent, 0, filecontent.Length);
                bw.Close();
            }
        }

QED

Comments