Passing C# variable to HTML page
-
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"/>
-
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"/>
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
-
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
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!
-
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"/>
I suggest you modify your
img
tag to make it a server-side tag, and modify it'ssrc
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
-
I suggest you modify your
img
tag to make it a server-side tag, and modify it'ssrc
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
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();
}