Example #1
1
 public FileStreamResult GetSample4()
 {
     var pdf = Sample4.GetSample(Server.MapPath("../bin"));
     string s = pdf.Output("ap.pdf", OutputDevice.ReturnAsString);
     MemoryStream m = new MemoryStream(FPdf.PrivateEncoding.GetBytes(s));
     var result = new FileStreamResult(m, "application/pdf");
     return result;
 }
Example #2
1
        public ActionResult Download(string id)
        {
            var filemodel = new FileModel();
            filemodel.ID = ObjectId.Parse(id);

            var fs = new FileStreamResult(_repository.DownloadFile(filemodel), " application/octet-stream");
            fs.FileDownloadName = filemodel.Filename;
            return fs;
        }
Example #3
0
        public FileStreamResult CreateVerificationFile(Guid IdAudience)
        {
            AudienceDocument _audience = GetAudienceById(IdAudience.ToString());

            if (_audience != null)
            {
                string datafile = _audience.VerificationString;

                if (datafile.Length > 0)
                {
                    var byteArray = System.Text.Encoding.ASCII.GetBytes(datafile);
                    var stream    = new System.IO.MemoryStream(byteArray);

                    System.Web.Mvc.FileStreamResult _sfile = new System.Web.Mvc.FileStreamResult(stream, "text/plain");
                    _sfile.FileDownloadName = "kindads.txt";

                    return(_sfile);
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
        private FileStreamResult WebsiteImage(string url)
        {
            var defaultAvatarAsBase64 = "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";

            var imageStream = new MemoryStream();
            try
            {
                var imageUrl = url;
                var request  = (HttpWebRequest)WebRequest.Create(imageUrl);
                var response = (HttpWebResponse)request.GetResponse();

                if (response.StatusCode != HttpStatusCode.OK) throw new Exception("GOTO_CATCH");
                using (var stream = response.GetResponseStream())
                {
                    using (var tempStream = new MemoryStream())
                    {
                        stream.CopyTo(tempStream);
                        imageStream = new MemoryStream(tempStream.ToArray());
                    }
                }
            }
            catch
            {
                var bytes   = Convert.FromBase64String(defaultAvatarAsBase64);
                imageStream = new MemoryStream(bytes);
            }

            var result = new FileStreamResult(imageStream, "image/jpeg");

            result.FileDownloadName = string.Format("{0}.jpg",
                Identity.Owner.WebAlias);

            return result;
        }
Example #5
0
        public FileStreamResult CreateTelemetryScript(string IdUser, string IdSite)
        {
            SiteEntity _site = GetSiteById(IdSite.ToString());

            if (_site != null)
            {
                string datafile = CreateTelemetryScriptContent(IdUser, IdSite);

                if (datafile.Length > 0)
                {
                    var byteArray = System.Text.Encoding.ASCII.GetBytes(datafile);
                    var stream    = new System.IO.MemoryStream(byteArray);

                    System.Web.Mvc.FileStreamResult _sfile = new System.Web.Mvc.FileStreamResult(stream, "text/plain");
                    _sfile.FileDownloadName = "adsMonetizationScript.txt";

                    return(_sfile);
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
        /// <summary>
        /// GET: /Reporting/Alarms/Export/
        /// </summary>
        /// <param name="id">Id of the operation.</param>
        /// <returns></returns>
        public ActionResult Export(int id)
        {
            try
            {
                using (var service = ServiceFactory.GetCallbackServiceWrapper<IOperationService>(new OperationServiceCallback()))
                {
                    Operation operation = service.Instance.GetOperationById(id);
                    Stream stream = ExportUtilities.ExportOperation(operation);

                    FileStreamResult result = new FileStreamResult(stream, MediaTypeNames.Text.Xml);
                    result.FileDownloadName = string.Format("{0}.xml", id);
                    return result;
                }
            }
            catch (EndpointNotFoundException)
            {
                // Silently ignore this exception.
            }
            catch (Exception ex)
            {
                Logger.Instance.LogException(this, ex);
            }

            return new HttpStatusCodeResult(HttpStatusCode.InternalServerError);
        }
Example #7
0
        public FileStreamResult CreateScriptFile(Guid IdAudience)
        {
            AudienceManager  repository = new AudienceManager();
            AudienceDocument _audience  = repository.GetAudienceById(IdAudience.ToString());

            if (_audience != null)
            {
                string datafile = CreateScriptGtm(IdAudience);

                if (datafile.Length > 0)
                {
                    var byteArray = System.Text.Encoding.ASCII.GetBytes(datafile);
                    var stream    = new System.IO.MemoryStream(byteArray);

                    System.Web.Mvc.FileStreamResult _sfile = new System.Web.Mvc.FileStreamResult(stream, "text/plain");
                    _sfile.FileDownloadName = "scriptGTM.txt";

                    return(_sfile);
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
Example #8
0
 public static FileStreamResult CreateFileStreamResult(Stream document, string outputName, ContentTypes contentType)
 {
     string sMimeType = GetContentType(contentType);
     FileStreamResult oResult = new FileStreamResult(document, sMimeType);
     oResult.FileDownloadName = outputName;
     return oResult;
 }
Example #9
0
		public FileResult DownloadOrderRecieptFiles(int orderId, bool isParentOrderDocumentsInclude = false)
		{
			var filesIds = _orderService.GetOrdersRecieptFileIds(orderId, isParentOrderDocumentsInclude);

			if (filesIds.Count() > 1)
			{
				var archiveBytes = _archiveService.GetArchivedFiles(filesIds);

				var workStream = new MemoryStream(archiveBytes);
				var fileResult = new FileStreamResult(workStream, MediaTypeNames.Application.Zip);
				fileResult.FileDownloadName = "Order Receipts.zip";
				return fileResult;
			}
			if (filesIds.Count() == 1)
			{
				var fileId = filesIds.First();
				var documentInfo = _documentService.GetDocumentInfo(fileId);
				var documentBytes = _documentService.GetDocument(fileId);

				if (documentInfo.IsEncrypted)
				{
					documentBytes = _cryptographicProvider.Decrypt(documentBytes).Value;
				}
				string fileName = documentInfo.Name + documentInfo.DocumentType;
				return File(documentBytes, "application/octet-stream", fileName);
			}
			return null;
			
		}
Example #10
0
        public FileStreamResult CreateScriptFile(Guid IdSite)
        {
            SiteEntity _site = GetSiteById(IdSite.ToString());

            if (_site != null)
            {
                string datafile = CreateScriptGtm(IdSite);

                if (datafile.Length > 0)
                {
                    var byteArray = System.Text.Encoding.ASCII.GetBytes(datafile);
                    var stream    = new System.IO.MemoryStream(byteArray);

                    System.Web.Mvc.FileStreamResult _sfile = new System.Web.Mvc.FileStreamResult(stream, "text/plain");
                    _sfile.FileDownloadName = "scriptGTM.txt";

                    return(_sfile);
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
        public FileStreamResult Download(int id)
        {
            ata ataa = controle.RetornaItem(id);

            FileStreamResult f = new FileStreamResult(new FileStream(ataa.caminhoArquivo,FileMode.Open), Path.GetExtension(ataa.caminhoArquivo));
            f.FileDownloadName = Path.GetFileName(ataa.caminhoArquivo);
            return f;
        }
Example #12
0
        public void ConstructorSetsFileStreamProperty() {
            // Arrange
            Stream stream = new MemoryStream();

            // Act
            FileStreamResult result = new FileStreamResult(stream, "contentType");

            // Assert
            Assert.AreSame(stream, result.FileStream);
        }
        public FileResult Index(string date)
        {
            MemoryStream memStream = new MemoryStream();
            StreamWriter writer = new StreamWriter(memStream);

            writer.Flush();
            memStream.Seek(0, SeekOrigin.Begin);
            FileStreamResult file = new FileStreamResult(memStream, "text/csv");
            file.FileDownloadName = String.Format("export_log_notification_{0}.csv", date);
            return file;
        }
Example #14
0
        /// <summary>
        /// GET: /Reporting/Alarms/Export/
        /// </summary>
        /// <param name="id">Id of the operation.</param>
        /// <returns></returns>
        public ActionResult Export(int id)
        {
            using (var service = ServiceFactory.GetCallbackServiceWrapper<IOperationService>(new OperationServiceCallback()))
            {
                Operation operation = service.Instance.GetOperationById(id);
                Stream stream = ExportUtilities.ExportOperation(operation);

                FileStreamResult result = new FileStreamResult(stream, "text/xml");
                result.FileDownloadName = string.Format("{0}.xml", id);
                return result;
            }
        }
 public ActionResult CaptureShot(FormCollection formCollection)
 {
     var capturedImage = formCollection["captured-Image"];
     var trimmedData = capturedImage.Replace("data:image/png;base64,", "");
     var imageFileName = formCollection["tab-name"] ?? "image";
     byte[] imageAsBytes = Convert.FromBase64String(trimmedData);
    
     var stream = new MemoryStream(imageAsBytes);
     var result = new FileStreamResult(stream,"image/png");
     result.FileDownloadName = imageFileName.Trim() + ".png";
     return result;
 }
Example #16
0
        public ActionResult Code128(string id)
        {
            var ms = new MemoryStream (4 * 1024);
            var img = Code128Rendering.MakeBarcodeImage (id, 2, false);

            img.Save (ms, ImageFormat.Png);
            ms.Seek (0, SeekOrigin.Begin);
            var result = new FileStreamResult (ms, "image/png");
            result.FileDownloadName = string.Format ("{0}.png", id);

            return result;
        }
 public static ActionResult GetAttachmentResult(this IDocumentSession documentSession, string key)
 {
     var attachment = documentSession.Advanced.DatabaseCommands.GetAttachment(key);
     if (attachment != null)
     {
         var result = new FileStreamResult(attachment.Data(), attachment.Metadata["content-type"].Value<string>())
         {
             FileDownloadName = key
         };
         return result;
     }
     return null;
 }
        public ActionResult ByUser(string fromDate, string toDate)
        {
            DateTime from = DateTime.Parse(fromDate);
            DateTime to = DateTime.Parse(toDate);

            Stream stream = new MemoryStream();
            Models.Report report = new Models.ByUserReport(from, to.AddDays(1));
            report.Write(stream);
            stream.Seek(0, SeekOrigin.Begin);
            FileStreamResult result = new FileStreamResult(stream, "application/excel");
            result.FileDownloadName = String.Format("timesheetByUser_{0}_{1}.xls", from.ToString("yyyyMMdd"), to.ToString("yyyyMMdd"));
            return result;
        }
Example #19
0
 public FileStreamResult ReadFileStreamResult(FileHandle handle)
 {
     _MIMEType = "image/jpg";// GetFileMimeType(handle.FileName);
     FileStreamResult FileStreamResult  = null;
     string  FullFilePath   =   handle.FilePath + @"\" +  handle.FileName;
     if (File.Exists(FullFilePath))
     {
         using (FileStream fileStream = System.IO.File.Open(FullFilePath,FileMode.Open))
         {
             FileStreamResult = new FileStreamResult(fileStream, _MIMEType);
         }
     }
     return FileStreamResult;
 }
        public ActionResult Find(string id, string filename)
        {
            if (id == null || filename == null)
            {
                return HttpNotFound();
            }

            var filePath = Path.Combine(_StorageRoot, id + "-" + filename);

            FileStreamResult result = new FileStreamResult(new System.IO.FileStream(filePath, System.IO.FileMode.Open), GetMimeType(filePath));
            result.FileDownloadName = filename;

            return result;
        }
        public ActionResult Index(InputModel model)
        {
            if (ModelState.IsValid)
            {
                var parser = new InputParser();
                using (var stream = parser.Parse(model))
                {
                    var result = new FileStreamResult(stream, "audio/wav");
                    result.FileDownloadName = model.NumberAsString + ".wav";
                }
            }

            return View(model);
        }
Example #22
0
 /// <summary>
 /// Enables processing of the result of an action method by a custom type that inherits from the <see cref="T:System.Web.Mvc.ActionResult"/> class.
 /// </summary>
 /// <param name="context">The context in which the result is executed. The context information includes the controller, HTTP content, request context, and route data.</param>
 public override void ExecuteResult(ControllerContext context)
 {
     var resolveResult = ResolveImage(context);
     if (resolveResult != null)
     {
         var fileStreamResult = new FileStreamResult(resolveResult.Stream, resolveResult.MimeType);
         fileStreamResult.ExecuteResult(context);
     }
     else
     {
         //TODO: let user specify default image if requested one was not found
         new EmptyResult().ExecuteResult(context);
     }
 }
 public FileResult DownloadMail(string mailId)
 {
     if (mailId.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) > 0)
     {
         throw new ArgumentException("Invalid characters in mailId", "mailId");
     }
     var filePath = Path.Combine(Properties.Settings.Default.MailDir, mailId);
     if (!MailHelper.ListMailFiles(Properties.Settings.Default.MailDir).Select(f => f.FullName).Contains(filePath))
     {
         throw new ArgumentException("mailId is not in white list", "mailId");
     }
     var result = new FileStreamResult(new FileStream(filePath, FileMode.Open), "message/rfc822");
     result.FileDownloadName = mailId;
     return result;
 }
        public FileStreamResult AssuranceImage(string consumerKey, string consumerSecret, string accessToken, string accessTokenSecret, string type)
        {
            var apiWrapper = new miiCard.Consumers.Service.v1.MiiCardOAuthClaimsService(consumerKey, consumerSecret, accessToken, accessTokenSecret);

            FileStreamResult result = null;
            try
            {
                result = new FileStreamResult(apiWrapper.AssuranceImage(type), "image/png");
            }
            catch (Exception ex)
            {
                result = new FileStreamResult(new MemoryStream(), "image/png");
            }

            return result;
        }
        /// <summary>
        /// Qr Code generation
        /// </summary>
        /// <param name="barcodeText"></param>
        /// <returns></returns>
        public ActionResult BarcodeImage(String barcodeText)
        {
            // generating a barcode here. Code is taken from QrCode.Net library
            QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
            QrCode qrCode = new QrCode();
            qrEncoder.TryEncode(barcodeText, out qrCode);
            GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(4, QuietZoneModules.Four), Brushes.Black, Brushes.White);
            Stream memoryStream = new MemoryStream();
            renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, memoryStream);

            // very important to reset memory stream to a starting position, otherwise you would get 0 bytes returned
            memoryStream.Position = 0;
            var resultStream = new FileStreamResult(memoryStream, "image/png");
            resultStream.FileDownloadName = String.Format("{0}.png", barcodeText);
            return resultStream;
        }
        public ActionResult BarcodeImage(String barcodeText)
        {
            QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
            QrCode qrCode = new QrCode();
            qrEncoder.TryEncode(barcodeText, out qrCode);
            GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(4, QuietZoneModules.Four), Brushes.Black, Brushes.White);

            Stream memoryStream = new MemoryStream();
            renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, memoryStream);

            memoryStream.Position = 0;

            var resultStream = new FileStreamResult(memoryStream, "image/png");
            resultStream.FileDownloadName = String.Format("{0}.png", barcodeText);

            return resultStream;
        }
Example #27
0
        public ActionResult Serve(string pathInfo)
        {
            var context = ControllerContext.HttpContext;
            var fileName = Path.GetFileName(pathInfo);
            var absolutePath = Server.MapPath(fileName);
            if (!System.IO.File.Exists(absolutePath))
            {
                return NotFound();
            }

            // A better test of uniqueness than modified date
            var etag = GenerateETag(ControllerContext, absolutePath);
            if (etag.StartsWith("404"))
            {
                // 404 (NotFound)
                return NotFound();
            }

            if (BrowserIsRequestingFileIdentifiedBy(etag))
            {
                // 304 (If-None-Match)
                return NotModified();
            }

            if (!System.IO.File.Exists(absolutePath))
            {
                // 404 (NotFound)
                return NotFound();
            }

            var lastModified = new FileInfo(absolutePath).LastWriteTime;
            if (BrowserIsRequestingFileUnmodifiedSince(lastModified))
            {
                // 304 (If-Last-Modified)
                return NotModified();
            }
            
            // 200 - OK
            CacheOnClient(context, etag, lastModified);
            var content = CacheOrFetchFromServer(absolutePath);
            var contentType = MimeType(absolutePath);
            var stream = new MemoryStream(content);
            var result = new FileStreamResult(stream, contentType);
            return result;
        }
Example #28
0
		/// <summary>
		/// Exports the pages of site including their history as a single XML file.
		/// </summary>
		/// <returns>A <see cref="FileStreamResult"/> called 'roadkill-export.xml' containing the XML data.
		/// If an error occurs, the action adds the error message to the TempData 'ErrorMessage' item.</returns>
		public ActionResult ExportAsXml()
		{
			try
			{
				Stream stream = _wikiExporter.ExportAsXml();

				FileStreamResult result = new FileStreamResult(stream, "text/xml");
				result.FileDownloadName = "roadkill-export.xml";

				return result;
			}
			catch (IOException e)
			{
				Log.Warn(e, "Unable to export as XML");
				TempData["ErrorMessage"] = string.Format(SiteStrings.SiteSettings_Tools_ExportXml_Error, e.Message);

				return RedirectToAction("Index");
			}
		}
        public ActionResult BarcodeImage(string secretKey, string userName)
        {
            string barcodeText = string.Format("otpauth://totp/Dentco%3A%20{0}?secret={1}", userName, secretKey);

            QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
            QrCode qrCode = new QrCode();
            qrEncoder.TryEncode(barcodeText, out qrCode);
            GraphicsRenderer renderer = new GraphicsRenderer(new FixedCodeSize(200, QuietZoneModules.Zero), Brushes.Black, Brushes.White);

            Stream memoryStream = new MemoryStream();
            renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, memoryStream);

            memoryStream.Position = 0;

            var resultStream = new FileStreamResult(memoryStream, "image/png");
            resultStream.FileDownloadName = string.Format("{0}.png", barcodeText);

            return resultStream;
        }
        public ActionResult DownloadSchema(long id)
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(id);
            string name = metadataStructure.Name;

            string path = OutputMetadataManager.GetSchemaDirectoryPathFromMetadataStructure(id);

            ZipFile zip = new ZipFile();
            if (Directory.Exists(path))
                zip.AddDirectory(path);

            MemoryStream stream = new MemoryStream();
            zip.Save(stream);
            stream.Position = 0;
            var result = new FileStreamResult(stream, "application/zip")
            { FileDownloadName = name+".zip" };

            return result;
        }
Example #31
0
 public ActionResult GetLeaveReport(LeaveReportFilterDTO model)
 {
     ActionResult result = null;
     try
     {
         DateTime fromDate = model.fromDate.HasValue ? model.fromDate.Value : DateTime.Today;
         DateTime toDate = model.toDate.HasValue ? model.toDate.Value : fromDate.AddDays(6);
         string excelFilePath = this.GenerateLeaveReport(model);
         if (!string.IsNullOrEmpty(excelFilePath))
         {
             Stream stream = this.LoadFile(excelFilePath);
             string downloadFileName = string.Format("Leave_Report({0}-{1}).xlsx", fromDate.ToString("yyyyMMdd"), toDate.ToString("yyyyMMdd"));
             string contentType = this.GetContentType(".xlsx");
             result = new FileStreamResult(stream, contentType) { FileDownloadName = downloadFileName };
         }
     }
     catch
     {
         result = Content("Download Fail");
     }
     return result;
 }
Example #32
0
        public static nameFile.FileStreamResult GerarArquivo(string nomeArquivo, Stream stream, string contentType, bool dataHoraControleAcesso = false)
        {
            try
            {
                stream.Seek(0, SeekOrigin.Begin);

                if (dataHoraControleAcesso)
                {
                    stream = Tecnomapas.Blocos.Etx.ModuloRelatorio.ITextSharpEtx.PdfMetodosAuxiliares.AdicionarDataHoraControleAcesso(stream);
                }

                nameFile.FileStreamResult fileResult = new nameFile.FileStreamResult(stream, contentType);
                fileResult.FileDownloadName = nomeArquivo;
                return(fileResult);
            }
            catch (Exception exc)
            {
                Validacao.AddErro(exc);
            }

            return(null);
        }
        private SystemMVC.ActionResult GetActionResult(string hash, bool streaming)
        {
            var path      = paths[hash];
            var extension = SystemIO.Path.GetExtension(path);

            extension = extension.Substring(1);

            var fileInfo = new SystemIO.FileInfo(path);
            var lenght   = fileInfo.Length;

            string mimeType = null;

            if ("mp4".Equals(extension))
            {
                mimeType = "video/mp4";
            }
            if ("mpe".Equals(extension))
            {
                mimeType = "video/mpeg";
            }
            if ("mpeg".Equals(extension))
            {
                mimeType = "video/mpeg";
            }
            if ("mpg".Equals(extension))
            {
                mimeType = "video/mpeg";
            }
            if ("mov".Equals(extension))
            {
                mimeType = "video/quicktime";
            }
            if ("mxf".Equals(extension))
            {
                mimeType = "application/mxf";
            }
            if ("pdf".Equals(extension))
            {
                mimeType = "application/pdf";
            }

            if (mimeType == null)
            {
                Trace.TraceWarning("FileController: unknown file extension: " + extension + "\n sending as application/octet-stream");
                mimeType = "application/octet-stream";
            }

            var fileStream = SystemIO.File.OpenRead(path);

            SystemMVC.FileStreamResult result = null;
            if (streaming)
            {
                result = new VideoStreamResult(fileStream, mimeType, lenght);
            }
            else
            {
                var filename = SystemIO.Path.GetFileName(path);
                result = new SystemMVC.FileStreamResult(fileStream, mimeType);
                result.FileDownloadName = filename;
            }

            return(result);
        }
Example #34
-1
 public ActionResult Index(string imageName)
 {
     FileStream stream = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "/images/logo.png", FileMode.Open, FileAccess.Read);
       FileStreamResult result = new FileStreamResult(stream, "image/png");
       result.FileDownloadName = "logo.png";
       return result;
 }
Example #35
-1
        // GET: Home/GZPost
        public FileResult GZPost(int id = 0)
        {
            if (id <= 0)
            { return null; }
            else
            {
                string fileName = GetFilePath(id);
                if (System.IO.File.Exists(fileName))
                {
                    System.IO.MemoryStream postMemory = new System.IO.MemoryStream();
                    using (System.IO.FileStream postFile = new System.IO.FileStream(fileName, System.IO.FileMode.Open))
                    {
                        postFile.CopyTo(postMemory);
                        postFile.Close();
                    }
                    postMemory.Position = 0;
                    FileStreamResult model = new FileStreamResult(postMemory, "application/json");
                    Response.AppendHeader("Content-Encoding", "gzip");

                    return model;
                }
                else
                { return null; }
            }
        }
Example #36
-1
 private static FileStreamResult FileStreamResult(Stream file)
 {
     var memoryStream = new MemoryStream();
     Fst2Scr.Fst2Scr.Convert(file, memoryStream);
     memoryStream.Seek(0, SeekOrigin.Begin);
     var fileStreamResult = new FileStreamResult(memoryStream, "application/octet-stream");
     return fileStreamResult;
 }