load a image from file

Hi
i??m tryng the .net and i don??t finde way to load a image since i have a database containing the name but in the server i have many folders how can i looad 0002.jpeg to my picture1


load a image from www\upload_image\1002.jpeg to my picture1

Thank you

Comments

  • edited 12:52PM
    the latest release of fastreport, new features have been added :

    Version 2017.1
    [Core]
    + added possibility to set picture location (URL) in PictureObject from database (I have not try this version)
    + .....


    if you use old the version of fastreport, you may use script in frx file.
    public class ReportScript
      {
    
        private void Data1_BeforePrint(object sender, EventArgs e)
        {
          Picture1.ImageLocation = (String)Report.GetColumnValue("MainReport.ImageColumn");
        }
      }
    

    in your asp.net code, the imagecolumn is referring to full path location of your images in the server, for example :
    HttpContext.Current.Server.MapPath("~/upload_image/") + "1001.jpeg"
    HttpContext.Current.Server.MapPath("~/upload_image/") + "1002.jpeg"
    ....
  • edited December 2016
    Thank??s i will give a try.

    Is it possible in the script to dinamic load from the database field ?
    HttpContext.Current.Server.MapPath("~/upload_image/")

    private void Data1_BeforePrint(object sender, EventArgs e)
    {

    +clienten/+ fotoN

    Thanks again for the help
  • edited December 2016
    I'm afraid you can't, you need a location (full path) in the server in order to set picture location, not virtual directory (../image/). To get full path, use function Server.MapPath in webform, or HttpContext.Current.Server.MapPath in MVC.

    if you want to do that in script, you must set a reference to use server.mappath function, never tried before.

    I will use this scenario :
    1. i have a datatable with fields :
    * ID int = 1
    * Name string = MyName
    * Picture string = 001.jpeg

    2. modify field Picture with full path location
    foreach (row in rows)
    {
    string img = row.Picture.ToString();
    row.Picture = HttpContext.Current.Server.MapPath("~/upload_image/") + img;
    }

    3. push datatable to fastreport
    4. use script to attach column picture to PictureObject

    please inform in this forum if you have succeded with using server.mappath in the script. and about the performance speed.
  • edited December 2016
    I have tried your method, success :

    1. add referenced assemblies in fastreport designer, menu report => options => script => add =>
    in my case, x86 system, C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Web.dll

    2. script
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Data;
    using FastReport;
    using FastReport.Data;
    using FastReport.Dialog;
    using FastReport.Barcode;
    using FastReport.Table;
    using FastReport.Utils;
    using System.Web;
    
    namespace FastReport
    {
      public class ReportScript
      {
        string basePath = HttpContext.Current.Server.MapPath("~/Content/");
        private void PageHeader1_BeforePrint(object sender, EventArgs e)
        {                                                                                     
           Picture1.ImageLocation = basePath + "login.png";
        }
      }
    }
    

    3. maybe, easier method, just passing HttpContext.Current.Server.MapPath("~/Content/") as report parameter, no need to set reference in the script, just Picture1.ImageLocation = (String)Report.GetParameterValue("ImageFullPath");
  • edited 12:52PM
    Thank??s i will try your solucion . It look??s what i need as new at .net thanks for the help

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.