Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Passing C# variable to HTML page

Passing C# variable to HTML page

Scheduled Pinned Locked Moved C#
csharphtmldata-structurestutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VengefulSakhmet
    wrote on last edited by
    #1

    This is probably pretty simple, but I'm a bit unsure of how to approach this. I have a path to a particular bmp file in my C# code. I want to display this picture in my HTML page. How would I pass this path to the HTML code instead of hardcoding the path? C#: string filePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\temp.bmp"; HTML (hard coded at the moment): <img src="C:\\Users\\L****\\AppData\\Local\\Program\\temp.bmp" alt="Graph"/>

    N A 2 Replies Last reply
    0
    • V VengefulSakhmet

      This is probably pretty simple, but I'm a bit unsure of how to approach this. I have a path to a particular bmp file in my C# code. I want to display this picture in my HTML page. How would I pass this path to the HTML code instead of hardcoding the path? C#: string filePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\temp.bmp"; HTML (hard coded at the moment): <img src="C:\\Users\\L****\\AppData\\Local\\Program\\temp.bmp" alt="Graph"/>

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      You can do this either in the code behind img.src = filePath or in the page <img src=<%=filePath%>


      only two letters away from being an asset

      V 1 Reply Last reply
      0
      • N Not Active

        You can do this either in the code behind img.src = filePath or in the page <img src=<%=filePath%>


        only two letters away from being an asset

        V Offline
        V Offline
        VengefulSakhmet
        wrote on last edited by
        #3

        I'm still a bit confused since I haven't worked with this before. The path: string filePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\temp.bmp"; is located in ChartContainer.ScreenShotWin. From what you wrote, I would assume I would make these changes to my hardcoded html file, but this is not solving passing filePath. File '<%=filePath%>' was not found. <%@ Language="C#" Inherits="ChartContainer.ScreenShotWin" %> <html> <head> <title></title> </head> <body> <img src=<%=filePath%> alt="Graph"/> </body> </html> What am I still misunderstanding? Thank you!

        1 Reply Last reply
        0
        • V VengefulSakhmet

          This is probably pretty simple, but I'm a bit unsure of how to approach this. I have a path to a particular bmp file in my C# code. I want to display this picture in my HTML page. How would I pass this path to the HTML code instead of hardcoding the path? C#: string filePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\temp.bmp"; HTML (hard coded at the moment): <img src="C:\\Users\\L****\\AppData\\Local\\Program\\temp.bmp" alt="Graph"/>

          A Offline
          A Offline
          Adam Maras
          wrote on last edited by
          #4

          I suggest you modify your img tag to make it a server-side tag, and modify it's src property somewhere in the loading stages of your form.

          And in your code, possibly in your Form_Load method, you would assign the value to it.

          string filePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\temp.bmp";
          graphImage.Src = filePath;

          Adam Maras | Software Developer Microsoft Certified Professional Developer

          V 1 Reply Last reply
          0
          • A Adam Maras

            I suggest you modify your img tag to make it a server-side tag, and modify it's src property somewhere in the loading stages of your form.

            And in your code, possibly in your Form_Load method, you would assign the value to it.

            string filePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\temp.bmp";
            graphImage.Src = filePath;

            Adam Maras | Software Developer Microsoft Certified Professional Developer

            V Offline
            V Offline
            VengefulSakhmet
            wrote on last edited by
            #5

            What type would graphImage.Src be defined as within my c# code? My code needs to save a picture to a local folder, navigate to an html file via webbrowser offscreen displaying said prior saved photo (by accessing it via the local folder path which I want to pass to it), take an offscreen screenshot, and save to file. In the end certain bits of data will also need to be created at runtime and displayed on the webbrowser for the screenshot. They want an image report. :| I guess I better start reading up on ASP. Everything else works fine except for accessing the picture in html without hardcoding it because I still am a bit in the dark about how this is passing the pathway to the image at runtime.

            <%@ Language="C#" Inherits="ChartContainer.ScreenShotWin" %>

            <html>
            <head>
            <title></title>
            </head>
            <body>
            <img alt="Missing Graph" runat="server" id="graphImage" />
            blah blah blah...

            private void ScreenShotWin_Load(object sender, EventArgs e)
            {
            filePath = Environment.GetFolderPat(Environment.SpecialFolder.LocalApplicationData) + "\\temp.bmp";
            webBrowser1.Navigate("C:\\Projects\\HTMLReport.htm");
            System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
            t.Interval = 1000;
            t.Tick += new EventHandler(t_Tick); //sets off the screenshot
            t.Start();
            }

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups