如何删除在C#中动态创建的动态html文件中的空格?在参考

时间:2022-03-20 09:17:08

I have create a html file and on the load of body a javascript function is getting called which has a name opencube()...Now I have written html and javascript code in c# like this.

我已经创建了一个html文件,并在正文的负载上调用了一个名为opencube()的javascript函数...现在我已经在c#中编写了html和javascript代码。

 protected void btnAddnew_Click(object sender, EventArgs e)
    {
        string sUrlHtml = "www.google.com";
        sServername1 = ddlServer.SelectedItem.Text;
        sTheme1 = ddlTheme1.SelectedValue;

        string sView = txtView.Text;
        string sView1 = sView.Trim();
        string sHeading = "cubus outperform EV Analytics";
        string sFileFullName;
        string sFilePath;
        string sFileName;
        string sTitle= "Test Ribbon8.0 by Rob Nidhansing";
        string sDataEtry = "";
        string slocalviw= "";
        string sExpot ="";

        sView1 = sView1.Replace(" ", "");
        if
           (DataEntryYes.Checked == true)
        {
            sDataEtry = "True";
        }
        else
        {
            sDataEtry = "False";
        }

        if
         (LocalViewYes.Checked == true)
        {
            slocalviw = "True";
        }
        else
        {
            slocalviw = "False";
        }

        if
            (ExportYes.Checked == true)
        {
            sExpot = "True";
        }
        else
        {
            sExpot = "False";
        }



        string strHTMLGrid = "";
        strHTMLGrid = strHTMLGrid + "<Html>\n";
        strHTMLGrid = strHTMLGrid + "<head>\n";
        strHTMLGrid = strHTMLGrid + "<meta http-equiv='X - UA - Compatible' content='IE = Edge' />\n";
        strHTMLGrid = strHTMLGrid + "<title>\n";
        strHTMLGrid = strHTMLGrid + "'" + sTitle + "' \n";
        strHTMLGrid = strHTMLGrid + "</title>\n";
        //Refrence in  javascript in (C#) of css files
        strHTMLGrid = strHTMLGrid + "<link rel='shortcut icon' href=' / EVServer / Images / favicon.ico' /> \n";
        strHTMLGrid = strHTMLGrid + "<link rel='icon' href=' / EVServer / Images / favicon.ico' /> \n";
        strHTMLGrid = strHTMLGrid + "<link rel='stylesheet' type='text / css' href=' / EVServer / UI / app.css' /> \n";
        strHTMLGrid = strHTMLGrid + "<link rel='stylesheet' type='text / css' href=' / EVServer / UI / kendo.common.core.css' /> \n";
        strHTMLGrid = strHTMLGrid + "<link rel='stylesheet' type='text / css' href=' / EVServer / UI / kendo.style.css' /> \n";

        //Refrence in  javascript in (C#) of script refrences
        strHTMLGrid = strHTMLGrid + "<script type='text / javascript' language='javascript' src=' / EVServer / CreateControl.js'> </script> \n";
        strHTMLGrid = strHTMLGrid + " <script type='text / javascript' language='javascript' src=' / EVServer / Client / ViewEnums.js'> </script> \n";
        strHTMLGrid = strHTMLGrid + "<script type='text / javascript' language='javascript' src=' / EVServer / UI / jquery.min.js'> </script> \n";
        strHTMLGrid = strHTMLGrid + " <script type='text / javascript' language='javascript' src=' / EVServer / UI / kendo.ui.core.min.js'> </script> \n";
        strHTMLGrid = strHTMLGrid + " <script type='text / javascript' language='javascript' src=' / EVServer / UI / ribbon.js'> </script> \n";
        strHTMLGrid = strHTMLGrid + " <script type='text / javascript' language='javascript' src=' / EVServer / UI / ev - ribbon - api.js'> </script> \n";
        strHTMLGrid = strHTMLGrid + "<script type='text / javascript' language='javascript' src=' / EVServer / UI / app.js'> </script> \n";

        strHTMLGrid = strHTMLGrid + "<script type='text / javascript' language='javascript' src= ' / EVServer / Client / ViewEnums.js'> </script> \n";
        strHTMLGrid = strHTMLGrid + "  <script>";
        //strHTMLGrid = strHTMLGrid + " < script>" +  "\n";
        strHTMLGrid = strHTMLGrid + " function ServerCredentials()  \n";
        strHTMLGrid = strHTMLGrid + " { \n";
        strHTMLGrid = strHTMLGrid + " return Array('Basant.Gera', 'KvY1bzqpXac28nUHf'); \n";
        strHTMLGrid = strHTMLGrid + " } \n";
        strHTMLGrid = strHTMLGrid + " function DataSourceCredentials()  \n";
        strHTMLGrid = strHTMLGrid + " { \n";
        strHTMLGrid = strHTMLGrid + " return Array('Basant.Gera', 'KvY1bzqpXac28nUHf'); \n";
        strHTMLGrid = strHTMLGrid + " } \n";


        // Scripts (Function) is defined here in C#
        strHTMLGrid = strHTMLGrid + "function OpenCube()" + "\n";
        strHTMLGrid = strHTMLGrid + " { \n";
        strHTMLGrid = strHTMLGrid + "EVObject.Enable(UIAuthorisationType.UIAuthorisationToolbar, true); \n ";
        strHTMLGrid = strHTMLGrid + "EVObject.Enable(UIAuthorisationType.UIAuthorisationTabBar, true); \n";
        strHTMLGrid = strHTMLGrid + "EVObject.TabBarPosition = TabBarPositionType.TabBarPositionBottom; \n";
        strHTMLGrid = strHTMLGrid + "EVObject.Allow(ActionAuthorisationType.UIAuthorisationToolbarText, false); \n";
        strHTMLGrid = strHTMLGrid + "EVObject.ToolBar.LargeButtons = false; \n";

        strHTMLGrid = strHTMLGrid + "EVObject.Enable(UIAuthorisationType.UIAuthorisationLocalViews, " + slocalviw + ")\n";
        strHTMLGrid = strHTMLGrid + "EVObject.Allow(ActionAuthorisationType.ActionAuthorisationDataEntry, " + sDataEtry + ");\n";
        strHTMLGrid = strHTMLGrid + "EVObject.Allow(ActionAuthorisationType.ActionAuthorisationSaveView, true);\n";
        strHTMLGrid = strHTMLGrid + "EVObject.Allow(ActionAuthorisationType.ActionAuthorisationExport, " + sExpot + ");\n";
        strHTMLGrid = strHTMLGrid + "EVObject.Allow(ActionAuthorisationType.ActionAuthorisationExportToExcel, true);\n";
        strHTMLGrid = strHTMLGrid + "EVObject.ViewLocations = 'General =/';\n";
        strHTMLGrid = strHTMLGrid + "EVObject.object.attachEvent('NeedDataSourceCredentials', DataSourceCredentials); \n";
        strHTMLGrid = strHTMLGrid + "EVObject.Enable(EVObject.object.attachEvent('NeedServerCredentials', ServerCredentials));\n";
        strHTMLGrid = strHTMLGrid + "EVObject.Views.Open(" + sView1 + ");\n";
        strHTMLGrid = strHTMLGrid + "LeaveBackstage(); \n";
        strHTMLGrid = strHTMLGrid + "ExpandRibbons(false); \n";
        strHTMLGrid = strHTMLGrid + "ShowBackstage(false); \n";
        strHTMLGrid = strHTMLGrid + " } \n";
        strHTMLGrid = strHTMLGrid + "  </script>";
        strHTMLGrid = strHTMLGrid + "</head>";
        // Html(C#) body is called here on the load of the opencube function which is defined above in javascript above in C#
        strHTMLGrid = strHTMLGrid + "<body onload='OpenCube() '>\n";
        strHTMLGrid = strHTMLGrid + "<h1>" + sHeading + "</h1>\n";
        strHTMLGrid = strHTMLGrid + "<div id='EVObject_xml' style='margin: 0px; position: absolute; top: 12px; left: 0px; bottom: 0px; right: 0px; '>\n";
        strHTMLGrid = strHTMLGrid + "<object name='EVObject' width='100%' height='100%' id='EVObject' codebase='" + sUrlHtml + "' lang='en-US' classid='clsid:80AC1200-0BBE-499A-A9E9-5F334DBC8E89'>\n";
        strHTMLGrid = strHTMLGrid + "<param name='Server' value='" + sServername1 + "'>\n";
        strHTMLGrid = strHTMLGrid + "<param name='EnableTabBar'  Value='True'>\n";
        strHTMLGrid = strHTMLGrid + "<param name='Theme' value='" + sTheme1 + "'>\n";
        strHTMLGrid = strHTMLGrid + "</object>\n";
        strHTMLGrid = strHTMLGrid + "</div>\n";
        strHTMLGrid = strHTMLGrid + "<div id='ribbon'>\n";
        strHTMLGrid = strHTMLGrid + "<div id='backstage - container'> </div>\n";
        strHTMLGrid = strHTMLGrid + "</div>\n";
        strHTMLGrid = strHTMLGrid + "</body>\n";
        strHTMLGrid = strHTMLGrid + "</Html>\n";







        sFilePath = Server.MapPath("");
        sFileName = "abc.html";
        sFileFullName = sFilePath + "\\" + sFileName;
        if (!Directory.Exists(sFilePath))
        {
            Directory.CreateDirectory(sFilePath);
        }
        // if it exist than to delete it.
        if (System.IO.File.Exists(sFileFullName))
        {
            System.IO.File.Delete(sFileFullName);
        }

        // If it deleted than we need to create it again
        FileStream fs = new FileStream(sFileFullName, FileMode.Create);
        using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
        {
            w.WriteLine(strHTMLGrid);
        }

        fs.Close();
        Page.ClientScript.RegisterStartupScript(this.GetType(), "", "fncpopup();", true);
    }

My file abc.html is created dynamically like this... but than i am getting spaces in the reference of css and scripts which i have given.. Like this.. How do i get rid of spaces...

我的文件abc.html是像这样动态创建的...但是我在css和脚本的引用中得到空格我已经给出了..就像这样..我如何摆脱空间......

Dynamic Abc.html which is generated in like this

Dynamic Abc.html就是这样生成的

<Html>
<head>
<meta http-equiv='X - UA - Compatible' content='IE = Edge' />
<title>
'Test Ribbon8.0 by Rob Nidhansing' 
</title>
<link rel='shortcut icon' href=' / EVServer / Images / favicon.ico' /> 
<link rel='icon' href=' / EVServer / Images / favicon.ico' /> 
<link rel='stylesheet' type='text / css' href=' / EVServer / UI / app.css' /> 
<link rel='stylesheet' type='text / css' href=' / EVServer / UI / kendo.common.core.css' /> 
<link rel='stylesheet' type='text / css' href=' / EVServer / UI / kendo.style.css' /> 
<script type='text / javascript' language='javascript' src=' / EVServer / CreateControl.js'> </script> 
 <script type='text / javascript' language='javascript' src=' / EVServer / Client / ViewEnums.js'> </script> 
<script type='text / javascript' language='javascript' src=' / EVServer / UI / jquery.min.js'> </script> 
 <script type='text / javascript' language='javascript' src=' / EVServer / UI / kendo.ui.core.min.js'> </script> 
 <script type='text / javascript' language='javascript' src=' / EVServer / UI / ribbon.js'> </script> 
 <script type='text / javascript' language='javascript' src=' / EVServer / UI / ev - ribbon - api.js'> </script> 
<script type='text / javascript' language='javascript' src=' / EVServer / UI / app.js'> </script> 
<script type='text / javascript' language='javascript' src= ' / EVServer / Client / ViewEnums.js'> </script> 
  <script> function ServerCredentials()  
 { 
 return Array('Basantgera', 'abc@123'); 
 } 
 function DataSourceCredentials()  
 { 
 return Array('Basantgera', 'abc@123'); 
 } 
function OpenCube()
 { 
EVObject.Enable(UIAuthorisationType.UIAuthorisationToolbar, true); 
 EVObject.Enable(UIAuthorisationType.UIAuthorisationTabBar, true); 
EVObject.TabBarPosition = TabBarPositionType.TabBarPositionBottom; 
EVObject.Allow(ActionAuthorisationType.UIAuthorisationToolbarText, false); 
EVObject.ToolBar.LargeButtons = false; 
EVObject.Enable(UIAuthorisationType.UIAuthorisationLocalViews, False)
EVObject.Allow(ActionAuthorisationType.ActionAuthorisationDataEntry, False);
EVObject.Allow(ActionAuthorisationType.ActionAuthorisationSaveView, true);
EVObject.Allow(ActionAuthorisationType.ActionAuthorisationExport, True);
EVObject.Allow(ActionAuthorisationType.ActionAuthorisationExportToExcel, true);
EVObject.ViewLocations = 'General =/';
EVObject.object.attachEvent('NeedDataSourceCredentials', DataSourceCredentials); 
EVObject.Enable(EVObject.object.attachEvent('NeedServerCredentials', ServerCredentials));
EVObject.Views.Open(kl12ACUC);
LeaveBackstage(); 
ExpandRibbons(false); 
ShowBackstage(false); 
 } 
  </script></head><body onload='OpenCube() '>
<h1>cubus outperform EV Analytics</h1>
<div id='EVObject_xml' style='margin: 0px; position: absolute; top: 12px; left: 0px; bottom: 0px; right: 0px; '>
<object name='EVObject' width='100%' height='100%' id='EVObject' codebase='www.google.com' classid='clsid:80AC1200-0BBE-499A-A9E9-5F334DBC8E89'>
<param name='Server' value='kl12ACUC'>
<param name='EnableTabBar'  Value='True'>
<param name='Theme' value='Ribbon'>
</object>
</div>
<div id='ribbon'>
<div id='backstage - container'> </div>
</div>
</body>
</Html>

If can see the spaces in between in reference to css and js file how to get rid of it.

如果可以看到介于css和js文件之间的空格如何摆脱它。

1 个解决方案

#1


0  

Have your tried Regular Expression? This is helpful in removing white-spaces from various files.

你试过正则表达吗?这有助于从各种文件中删除空格。

#1


0  

Have your tried Regular Expression? This is helpful in removing white-spaces from various files.

你试过正则表达吗?这有助于从各种文件中删除空格。