locked
How to display and upload image in dynamic datasite asp.net webform RRS feed

  • Question

  • User1007437673 posted

    I'm working on dynamic datasite LINQ SQL admin panel where tables are displayed to edit, insert or delete. In a table , Image Column it shows the url of image. I want to display the image instead of URL. and when edit there should be a file upload button and file should be saved in folder of website. Type for Image= navarchar MAX

    Tuesday, February 23, 2021 12:11 PM

All replies

  • User475983607 posted

    Use the image tag to display an image.

    https://www.w3schools.com/tags/tag_img.asp

    File upload is covered in the official docs for the unknown framework you are working in.

    https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-5.0

    If you need further assistance, share your code.  Explain the expected results and the actual results. 

    Tuesday, February 23, 2021 12:19 PM
  • User-1330468790 posted

    Hi salmanm22,

     

    You should share the codes so that we know how you implement this dynamic data in webforms.

    Regarding how to display the image instead of URL, you could directly assign the url to the image control or convert the image to base64 format and assign the value to the image control.

    If the control is of type dynamic, you might need to find dynamic control in the project and modify it as an image control in code behind.

    Convert image to base64:

    using (Image image = Image.FromFile(imagePath))
    {
        using (MemoryStream m = new MemoryStream())
        {
            image.Save(m, image.RawFormat);
            byte[] imageBytes = m.ToArray();
    
            // Convert byte[] to Base64 String
            string base64String = Convert.ToBase64String(imageBytes);
            // Assign the base64 string to the Image control
            Image1.ImageUrl = "data:image/png;base64," + base64String;
        }
    }

     

    Hope helps.

    Best regards,

    Sean

    Wednesday, February 24, 2021 3:18 AM