Exemple #1
0
        public async Task <HttpResponseMessage> FileDownload(Guid id, Guid fileId)
        {
            var note             = repo_.GetClientNote(id, fileId);
            var originalFileName = note.Text;

            var uploadDir = await openFileShare();

            var shareDir  = uploadDir.GetDirectoryReference(id.ToString());
            var shareFile = shareDir.GetFileReference(fileId.ToString());

            var localFilename = DownloadFilename(fileId);
            await shareFile.DownloadToFileAsync(localFilename, FileMode.Create);

            HttpResponseMessage userFile = new HttpResponseMessage(HttpStatusCode.OK);

            userFile.Content = new StreamContent(new FileStream(localFilename, FileMode.Open));
            userFile.Content.Headers.ContentType        = new System.Net.Http.Headers.MediaTypeHeaderValue(MIMEAssistant.GetMIMEType(originalFileName));
            userFile.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
            {
                FileName = originalFileName
            };
            return(userFile);
        } // FileDownload
        public HttpResponseMessage FileDownload(Guid fileId)
        {
            var fileName = HttpContext.Current.Server.MapPath(String.Format("~/App_Data/Uploads/{0}.zip", fileId));

            HttpResponseMessage userFile = new HttpResponseMessage(HttpStatusCode.OK);

            userFile.Content = new StreamContent(new FileStream(fileName, FileMode.Open));
            userFile.Content.Headers.ContentType        = new System.Net.Http.Headers.MediaTypeHeaderValue(MIMEAssistant.GetMIMEType("full-export.zip"));
            userFile.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
            {
                FileName = "full-export.zip"
            };
            return(userFile);
        } // FileDownload