在 Web 应用程序中使用 C# 显示图像 [英] Display an Image using C# in Web Application

查看:30
本文介绍了在 Web 应用程序中使用 C# 显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Web 应用程序,我在其中构建了一个生成报告的 C# 类.生成此报告需要近 40 秒,因为它会在数百个文件夹中搜索某些文件.所以我希望有一种方法可以在生成此报告时显示正在加载..."图标.我有一个 gif 存储在我的图像文件夹中,这将是完美的.我在这一点上所做的研究主要是谈论可以保存图像的图片框和图像控件,但我希望只有一种方法可以在创建报告时在报告上方显示图像.

Web 应用程序来自 Web ADF Geocortex 网站,我再次创建了一个 C# 类来生成此报告.下面是一些可能有帮助的代码.

////<摘要>///使用中的数据为当前报告生成 HTML///给定的表.///</总结>///<param name="reportLayers">要包含在报告中的图层.</param>///<返回>公共覆盖字符串 GenerateReportHtml(ListreportLayers){StringBuilder htmlString = new StringBuilder();StringWriter stringWriter = new StringWriter(htmlString);HtmlTextWriter writer = new HtmlTextWriter(stringWriter);字符串holdAPI = "";列表<字符串>排除 = GetExcludedFields();foreach(reportLayers 中的 ReportLayer 层){string[] strFiles = null;布尔值 = 假;if (layer.Layer.Name == "底孔位置 (OP)")writer.RenderBeginTag(HtmlTextWriterTag.P);//<p>writer.RenderBeginTag(HtmlTextWriterTag.Strong);//<强>writer.Write(layer.Layer.Name);writer.RenderEndTag();//结束writer.RenderEndTag();//结束</p>writer.WriteBreak();//<br/>foreach(layer.ReportFeatures 中的 ReportFeature 特征){//每个特征都在一个表中writer.RenderBeginTag(HtmlTextWriterTag.Table);//<表>foreach(feature.ReportFields 中的 ReportField 字段){字符串 fieldName = field.Alias;if (!exclusions.Contains(fieldName)){

解决方案

with this html...

<img src="Images/Load.Gif"/>

然后是一个 jQuery ajax post on document.ready..

当 ajax 调用返回时,您将 div html 替换为报告.这将删除图像.

I have a Web Application that I built a C# class in that generates a Report. This report takes nearly 40 seconds to generate because it searches hundreds of folders for certain files. So I was hoping there was a way to display a "Loading.." icon as this report is generating. I have a gif stored in my Images folder that would be perfect. The research that I've done at this point mostly talks about picturebox's and image controls that can hold the image but I was hoping there was just a way of displaying the image above the report while its being created.

The Web Application is from a Web ADF Geocortex website and again I created a C# class that generates this report. Below is some code that may help.

/// <summary>
    /// Generates HTML for the current report using the data in
    /// the given table.
    /// </summary>
    /// <param name="reportLayers">The layers to include in the report.</param>
    /// <returns>
    public override string GenerateReportHtml(List<ReportLayer> reportLayers)
    {
        StringBuilder htmlString = new StringBuilder();
        StringWriter stringWriter = new StringWriter(htmlString);
        HtmlTextWriter writer = new HtmlTextWriter(stringWriter);



        string holdAPI = "";

        List<string> exclusions = GetExcludedFields();

        foreach (ReportLayer layer in reportLayers)
        {
            string[] strFiles = null;
            Boolean val = false;

            if (layer.Layer.Name == "Bottom Hole Location (OP)")
            writer.RenderBeginTag(HtmlTextWriterTag.P); // <p>
            writer.RenderBeginTag(HtmlTextWriterTag.Strong); // <strong>
            writer.Write(layer.Layer.Name);

            writer.RenderEndTag(); // end </strong>
            writer.RenderEndTag(); // end </p>

            writer.WriteBreak(); // <br />
            foreach (ReportFeature feature in layer.ReportFeatures)
            {

            // each feature will be in a table
                writer.RenderBeginTag(HtmlTextWriterTag.Table); // <table>

                foreach (ReportField field in feature.ReportFields)
                {
                    string fieldName = field.Alias;
                    if (!exclusions.Contains(fieldName))
                    {

解决方案

with this html...

<div id="rpt">
    <img src="Images/Load.Gif" />
</div>

then a jQuery ajax post on document.ready..

<script type="text/javascript">
    $(function() {
        $.post("/path/to/report", function(reportHtml) {
            $("#rpt").html(reportHtml);
        });
    });
</script>

When the ajax call returns you replace the div html with report. This would remove the image.

这篇关于在 Web 应用程序中使用 C# 显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆