简体   繁体   English

package中添加图片资源并部署到Visual Studio中时,图片资源的文件路径是什么?

[英]What is the file path for image resources when you add them during package and deploy in Visual Studio?

I have made a html file that outputs a receipt for my C# application.我制作了一个 html 文件,输出了我的 C# 申请的收据。 In the html report I have a logo at the top of the receipt.在 html 报告中,我在收据顶部有一个徽标。 The image is in the debug folder and it works fine when I run it debugging.该图像位于调试文件夹中,当我运行它进行调试时它工作正常。

However when I package and deploy my application, the receipt loses the image.但是,当我 package 并部署我的应用程序时,收据丢失了图像。 I add the image as a resource when I package and deploy so I know its there.我在 package 和部署时将图像添加为资源,所以我知道它在那里。 I am assuming that I need to put the full path to access the image.我假设我需要输入完整路径才能访问图像。

However, I do not know what the path will be when we package and deploy.但是,我不知道我们 package 和部署时的路径是什么。 Where are the image resources we add when we package and deploy stored when we install the application?我们package时添加的图片资源和安装应用时deploy存储的图片资源在哪里?

Here is my function that creates my html file.这是我的 function,它创建了我的 html 文件。 Where I put the image source what do I need to put to get the logo to show up when I debug and when I package and deploy?我把图像源放在哪里,我需要放什么才能在我调试和部署 package 时显示徽标?

private StringBuilder GenerateReport()
{
    StringBuilder html = new StringBuilder();
    StringBuilder css = new StringBuilder();
    try
    {
        // CSS is a way to style the HTML page. Each HTML tag can be customized.
        // In this example, the H1 and TD tags are customized.
        // Refer to this website for examples: https://www.w3schools.com/Css/css_syntax.asp

        css.AppendLine("<style>");
        css.AppendLine("td {padding: 5px; text-align:center; font-weight: bold; text-align: center; font-size: 12px;}");
        css.AppendLine("h1 {color: orange;}");
        css.AppendLine("</style>");

        // HTML is used to format the layout of a webpage. This will be the frame
        // we use to place our data in. CSS is used to style the page to look a
        // certain way.

        // The <HTML> and </HTML> tags are the start and end of a webpage.
        // The <HEAD> and </HEAD> tags gives information about the webpage
        // such as the title and if there is any CSS styles being used.
        // The text between the <TITLE> and </TITLE> tags are used by the
        // browser to display the name of the page.
        // <BODY> and </BODY> is where the data of the page is stored
        // <H1> and </H1> is the largest font size for headings. These
        // can be from H1 to H6. H6 is the smallest font. https://www.w3schools.com/tags/tag_hn.asp

        html.AppendLine("<html>");
        css.AppendLine("<center {display: block;margin - left: auto;margin - right: auto;width: 50 %;}</center>");
        html.AppendLine($"<head>{css}<title>{"Receipt"}</title></head>");
        //css.AppendLine("<left {display: block;margin - left: auto;margin - right: auto;width: 50 %;}</left>");
        html.Append("<img src= Debug\\hunting.jpg style=' align: center; width: 75px; height: 50px;'>");
        html.AppendLine("<body>");

        html.AppendLine($"<h1>{" Order Receipt"}</h1>");
        html.Append($"<br></br>");
        html.Append($"<p style = 'text-indent: -550px; font-size: 15px'><b>{"Customer: " + strFirstName + " " + strLastName}</b></p>");
        html.Append($"<p style = 'text-indent: -550px; font-size: 15px'><b>{"Order Number: " + strMaxOrderID}</b></p>");
        html.Append($"<p style = 'text-indent: -550px; font-size: 10px'><b>{"Phone Number: " + strPhoneNumber}</b></p>");
        // Create table of data
        // <TABLE> and </TABLE> is the start and end of a table of rows and data.
        // <TR> and </TR> is one row of data. They contain <TD> and </TD> tags.
        // <TD> and </TD> represents the data inside of the table in a particular row.
        // https://www.w3schools.com/tags/tag_table.asp

        // I used an <HR /> tag which is a "horizontal rule" as table data.
        // You can "span" it across multiple columns of data.

        html.AppendLine("<table>");
        html.AppendLine("<tr><td>Item Name</td><td>Quantity</td><td>Price</td></tr>");
        html.AppendLine("<tr><td colspan=3><hr /></td></tr>");
        for (int i = 0; i < lstShoppingCartName.Count; i++)
        {
            html.Append("<tr>");
            html.Append($"<td>{lstShoppingCartName[i]}</td>");
            html.Append($"<td>{lstShoppingCartQuantity[i]}</td>");
            html.Append($"<td>{lstShoppingCartCost[i]}</td>");
            html.Append("</tr>");
            html.AppendLine("<tr><td colspan=4><hr /></td></tr>");
        }
        html.AppendLine("</table>");
        html.Append($"<br></br><br></br>");
        html.Append($"<p style = 'align:center; text-indent: 390px; font-size: 15px '><b>{"SubTotal: " + decSubTotal.ToString("C2")}</b></p>");
        html.Append($"<p style = 'align:center; text-indent: 371px; font-size: 15px '><b>{"Discount Percent: " + decDiscountPercent.ToString("N3")}</b></p>");
        html.Append($"<p style = 'align:center; text-indent: 422px; font-size: 15px '><b>{"Discount: " + decDiscount.ToString("C2")}</b></p>");
        html.Append($"<p style = 'align:center; text-indent: 297px; font-size: 15px '><b>{"SubTotal After Discount: " + decSubTotalDiscount.ToString("C2")}</b></p>");
        html.Append($"<p style = 'align:center; text-indent: 430px; font-size: 15px '><b>{"Taxes: " + decTaxes.ToString("C2")}</b></p>");
        html.Append($"<p style = 'align:center; text-indent: 450px; font-size: 20px ' ><b>{"Total: " + decTotal.ToString("C2")}</b></p>");
        html.Append($"<div><button onClick='window.print()'> {"Print this page"}</ button ></ div >");
        html.AppendLine("</body></html>");
    }
    catch(Exception ex)
    {
        MessageBox.Show(message + ex.Message, "Program Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    return html; // The returned value has all the HTML and CSS code to represent a webpage
}

if your logo isn't an huge image file, you could set it directly into the markup, using Base64 encoding, that transform an image into a string, to use instead of path.如果您的徽标不是一个巨大的图像文件,您可以使用 Base64 编码将其直接设置到标记中,将图像转换为字符串,以代替路径使用。

You can convert your logo into Base64 string using an online service like this您可以使用这样的在线服务将徽标转换为 Base64 字符串

and then add it to your HTML output this way然后通过这种方式将其添加到您的 HTML output

<img src="data:image/png;base64,#past here your image encoded text#">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将文件路径设置为Visual Studio 2005中的Resources文件夹 - Set the file path to Resources folder in Visual Studio 2005 什么是Visual Studio中的.deploy扩展 - What is .deploy extension in Visual Studio 通过GUI在Visual Studio中添加服务引用时,它会做什么? - What does it do when you add a service reference in Visual Studio, through the GUI? Visual Studio在构建期间部署报表项 - Visual Studio deploy report item during build Visual Studio 2013 Web部署程序包问题 - Visual Studio 2013 Web Deploy Package Issue 在不使用Visual Studio的情况下将nuget包添加到项目文件中 - Add nuget package into project file without Visual Studio "无法在 Visual Studio 2010 中编辑或添加引用文件的路径" - Cannot Edit or Add Path to Reference File in Visual Studio 2010 在Visual Studio中向Windows资源添加图标 - Add icon to Windows resources in Visual Studio 在Visual Studio中,当我尝试将记录添加到访问文件时:该字段太小,无法接受您尝试添加的数据量。 - In visual studio when i trying to add record to ACCESS file :The field is too small to accept the amount of data you attempted to add. 如何调试在加载过程中引发异常的Visual Studio加载项? - How do you debug a visual studio add-in that throws an exception during loading?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM