Esempio n. 1
0
        public RemoteFileInfo DownloadFile(DownloadRequest request)
        {
            // get some info about the input file
            string filePath = System.IO.Path.Combine("Upload", request.FileName);

            System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);

            // report start
            Console.WriteLine("Sending stream " + request.FileName + " to client");
            Console.WriteLine("Size " + fileInfo.Length);

            // check if exists
            if (!fileInfo.Exists)
            {
                throw new System.IO.FileNotFoundException("File not found", request.FileName);
            }

            // open stream
            System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            // return result
            RemoteFileInfo result = new RemoteFileInfo();

            result.FileName       = request.FileName;
            result.Length         = fileInfo.Length;
            result.FileByteStream = stream;
            return(result);

            // after returning to the client download starts. Stream remains open and on server and the client reads it, although the execution of this method is completed.
        }
Esempio n. 2
0
        public RemoteFileInfo DownloadFile(DownloadRequest request)
        {
            // get some info about the input file
            string filePath = System.IO.Path.Combine("Upload", request.FileName);
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);

            // report start
            Console.WriteLine("Sending stream " + request.FileName + " to client");
            Console.WriteLine("Size " + fileInfo.Length);

            // check if exists
            if (!fileInfo.Exists) throw new System.IO.FileNotFoundException("File not found", request.FileName);

            // open stream
            System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            // return result
            RemoteFileInfo result = new RemoteFileInfo();
            result.FileName = request.FileName;
            result.Length = fileInfo.Length;
            result.FileByteStream = stream;
            return result;

            // after returning to the client download starts. Stream remains open and on server and the client reads it, although the execution of this method is completed.
        }