I'm trying to format a literal control on a code-behind page:
BillerLiteral.Text = "<p class="'no-margin'"/>" + attendee1.FirstName + " " +
attendee1.LastName + "</p> <p class=""no-margin"">" + attendee1.Address1 + "," +
attendee1.Address2 + "</p><p class=""margin"">" + attendee1.City + "," +
attendee1.State + " " + attendee1.ZipCode + "</p><p>" + attendee1.Email + "</p>";
Right after I added that line, I get compilation errors even though it compiles fine.
Compilation Error Description: An error occurred during the compilation of a
resource required to service this request. Please review the following specific
error details and modify your source code appropriately.
Compiler Error Message: The compiler failed with error code 1.
Here's the detailed compiler output:
c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE> "c:\Window
\Microsoft.NET\Framework\v3.5\csc.exe" /t:library /utf8output /R:"C:\Windows
\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089
\System.ServiceModel.dll"
/R:"C:\Windows\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a
\System.Web.Services.dll" /R:"C:\Windows\assembly\GAC_32\System.Data
\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\assembly\GAC_MSIL
\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089
\System.Runtime.Serialization.dll" /R:"C:\Windows\assembly\GAC_MSIL\System
\2.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\assembly\GAC_MSIL
\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:
"C:\Windows\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35
\System.WorkflowServices.dll" /R:"C:\Windows\assembly\GAC_32\
System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\
System.EnterpriseServices.dll"
/R:"C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a
\System.Configuration.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.IdentityModel
\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\assembly
\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll" /R:
"C:\Windows\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a
\System.Web.Mobile.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Xml
\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"
C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll"
/R:"C:\Windows\assembly\GAC_MSIL\System.ServiceModel.Web
\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll"
/R:"C:\Windows\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35
\System.Web.Extensions.dll" /R:"C:\Windows\assembly\GAC_MSIL
\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089
\System.Data.DataSetExtensions.dll" /R:"C:\Users\jeffreyeas\AppData\Local
\Temp\Temporary ASP.NET Files\awchallenge\ae85f60c\8aef9183\App_Code.fkizkk6y.dll"
/R:"C:\Windows\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089
\System.Xml.Linq.dll" /R:"C:\Windows\assembly\GAC_32\System.Web
\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /out:"C:\Users\jeffreyeas\AppData\Local
\Temp\Temporary ASP.NET Files\awchallenge\ae85f60c\8aef9183
\App_Web_page_two.aspx.cdcab7d2.dkslispb.dll" /D:DEBUG /debug+ /optimize-
/win32res:"C:\Users\jeffreyeas\AppData\Local\Temp\Temporary ASP.NET Files\awchallenge
\ae85f60c\8aef9183\vuyv4kby.res" /w:4 /nowarn:1659;1699;1701 /warnaserror-
"C:\Users\jeffreyeas\AppData\Local\Temp\Temporary ASP.NET Files\awchallenge\ae85f60c
\8aef9183\App_Web_page_two.aspx.cdcab7d2.dkslispb.0.cs" "C:\Users\jeffreyeas\AppData
\Local\Temp\Temporary ASP.NET Files\awchallenge\ae85f60c\8aef9183
\App_Web_page_two.aspx.cdcab7d2.dkslispb.1.cs" "C:\Users\jeffreyeas\AppData\Local
\Temp\Temporary ASP.NET Files\awchallenge\ae85f60c\8aef9183
\App_Web_page_two.aspx.cdcab7d2.dkslispb.2.cs"
What am I missing?
Your quotes are wrong in "<p class="'no-margin'"/>"
BillerLiteral.Text = "<p class=\"no-margin\"/>" + attendee1.FirstName + " " + attendee1.LastName + "</p> <p class=\"no-margin\">" + attendee1.Address1 + "," + attendee1.Address2 + "</p><p class=\"margin\">" + attendee1.City + "," + attendee1.State + " " + attendee1.ZipCode + "</p><p>" + attendee1.Email + "</p>";
try this
Related
I'm trying to use httpcontext on a given string
ex:
I have this
string url = "https://subdomain.domain.com/link1/";
And I want to be able to retreive those following value from the string
Console.Write("<br/>Host " + HttpContext.Current.Request.Url.Host);
Console.Write("<br/>Authority: " + HttpContext.Current.Request.Url.Authority);
Console.Write("<br/>Port: " + HttpContext.Current.Request.Url.Port);
Console.Write("<br/>AbsolutePath: " + HttpContext.Current.Request.Url.AbsolutePath);
Console.Write("<br/>ApplicationPath: " + HttpContext.Current.Request.ApplicationPath);
Console.Write("<br/>AbsoluteUri: " + HttpContext.Current.Request.Url.AbsoluteUri);
Console.Write("<br/>PathAndQuery: " + HttpContext.Current.Request.Url.PathAndQuery);
Is there a way to do that?
Thanks #UweKeim for the answer.
I can definitely do that by using the Uri class.
Here's the sample of code for those who need it:
Uri uri = new Uri("https://subdomain.domain.com/link1/");
Console.WriteLine($"AbsolutePath: {uri.AbsolutePath}");
Console.WriteLine($"AbsoluteUri: {uri.AbsoluteUri}");
Console.WriteLine($"DnsSafeHost: {uri.DnsSafeHost}");
Console.WriteLine($"Fragment: {uri.Fragment}");
Console.WriteLine($"Host: {uri.Host}");
Console.WriteLine($"HostNameType: {uri.HostNameType}");
Console.WriteLine($"IdnHost: {uri.IdnHost}");
Console.WriteLine($"IsAbsoluteUri: {uri.IsAbsoluteUri}");
Console.WriteLine($"IsDefaultPort: {uri.IsDefaultPort}");
Console.WriteLine($"IsFile: {uri.IsFile}");
Console.WriteLine($"IsLoopback: {uri.IsLoopback}");
Console.WriteLine($"IsUnc: {uri.IsUnc}");
Console.WriteLine($"LocalPath: {uri.LocalPath}");
Console.WriteLine($"OriginalString: {uri.OriginalString}");
Console.WriteLine($"PathAndQuery: {uri.PathAndQuery}");
Console.WriteLine($"Port: {uri.Port}");
Console.WriteLine($"Query: {uri.Query}");
Console.WriteLine($"Scheme: {uri.Scheme}");
Console.WriteLine($"Segments: {string.Join(", ", uri.Segments)}");
Console.WriteLine($"UserEscaped: {uri.UserEscaped}");
Console.WriteLine($"UserInfo: {uri.UserInfo}");
I had a website created using Asp.Net framework 3.5 and And now I'm upgrading it to Visualstudio 2015 (framework 4.6)..
When click on any link it throws an error- Cannot use a leading .. to exit above the top directory
string mslinepath = ResolveUrl("~/" + dt_submenu.Rows[i].ItemArray[1].ToString().Trim());
string pagenamesub = mslinepath + "?Session=" + dt_submenu.Rows[i].ItemArray[2].ToString().Trim(); //"Framework.aspx?name=" +
// nav.InnerHtml += "<li> " + UppercaseFirstEach(dt_submenu.Rows[i].ItemArray[0].ToString().Trim()) + " ";
str += "<li> " + UppercaseFirstEach(dt_submenu.Rows[i].ItemArray[0].ToString().Trim()) + " ";
submenu(dt_submenu.Rows[i].ItemArray[3].ToString().Trim());
// nav.InnerHtml += "</li>";
If anyone knows the solution please let me know.. Thanks in advance
I had this problem and the answer was actually quite simple:
Open your master page and review all your include files, css, js, etc..
Replace:
href="../"
with
href="/"
In other words, the master page must use absolute path and not relative.
Since yesterday, I try to run a sample of code to display a chart with FusionCharts and Mvc3 Razor and nothing works. Please.... help!!! :)
Here is what I have done:
I took the projet from Libero. here
After that, I used the project convertor here to upgrade the project from Mvc2 to Mvc3.
When I try to run to code (F5 and show the result in browser), that works fine; all graphics are displayed correctly.
If I just create a new view with razor (.cshtml) instead of the current .aspx (replacing a view from the old syntax to the new razor) and I try to displayed the same graphic, the page is displayed correctly but without graphic. When I look into the page source with firebug or any other tools, no code is behind the scene. I also don't have any errors while looking with the Web Developer tool in Firefox.
I just tried to add a Html.Raw in front of the code that generate the javascript to not encode the output and I have the same result. Also trying with returning HtmlString but again same result; no graphic is displayed.
The key to don't miss in this problem is that if I try the exact same code but with an .aspx file, all is correct.
In .aspx, the code looks like this:
<%=Html.FChart("Chart01", ViewData["MyChart"], 600, 400)%>
And in .cshtml:
#{Html.FChart("Chart01", ViewData["MyChart"], 600, 400); }
And finally, the html helper to generate this bunch of code:
private static string RenderChart(string controlId, string xmlData, FusionChartBase chart, int width, int height)
{
String sControlId = controlId;
String sJsVarId = "_lib_JS_" + controlId;
String sDivId = "_lib_DIV_" + controlId;
String sObjId = "_lib_OBJ_" + controlId;
String sWidth = width.ToString();
String sHeight = height.ToString();
StringBuilder oBuilder = new StringBuilder();
oBuilder.AppendLine(#"<div id=""" + sDivId + #""" align=""center""></div>");
oBuilder.AppendLine(#"<script type=""text/javascript"">");
oBuilder.AppendLine(#"var " + sControlId + #" = (function() {");
oBuilder.AppendLine(#" return {");
oBuilder.AppendLine(#" containerId: '" + sDivId + "',");
oBuilder.AppendLine(#" xmlData: '',");
oBuilder.AppendLine(#" chartType: '',");
oBuilder.AppendLine(#" showChart: function() {");
oBuilder.AppendLine();
oBuilder.AppendFormat(#" var chartURL = '{0}' + this.chartType.replace('Chart', '{1}');", UrlSWF, SufixSWF);
oBuilder.AppendLine(#" var " + sJsVarId + #" = new FusionCharts(chartURL, """ + sObjId + #""", """ + sWidth + #""", """ + sHeight + #""");");
oBuilder.AppendLine(#" " + sJsVarId + #".setDataXML(this.xmlData);");
oBuilder.AppendLine(#" " + sJsVarId + #".render(""" + sDivId + #""");");
oBuilder.AppendLine(#" }");
oBuilder.AppendLine(#" }");
oBuilder.AppendLine(#"})();");
oBuilder.AppendLine(#"setTimeout(function(){");
oBuilder.AppendLine(#" " + sControlId + #".xmlData = """ + xmlData.Replace(#"""", #"'") + #""";");
oBuilder.AppendLine(#" " + sControlId + #".chartType = """ + chart.ChartType + #""";");
oBuilder.AppendLine(#" " + sControlId + #".showChart();");
oBuilder.AppendLine(#"},0);");
oBuilder.AppendLine(#"</script>");
return oBuilder.ToString();
}
I don't know if I must set some configuration options in the web.config or what I don't understand in the behavior of Mvc2 compare to Mvc3, but it's very frustrating.
If you have any idea, a big thanx in advance.
It should be #Html.FChart("Chart01", ViewData["MyChart"], 600, 400) instead of #{Html.FChart("Chart01", ViewData["MyChart"], 600, 400); }
FusionCharts provides a .NET library which makes rendering charts a one liner - read through the FusionCharts Documentation.
They have a recent tutorial up on their blog - JavaScript Charts with ASP.NET (C#) Using FusionCharts XT
When code is placed onClick event it does not show open save dialog box and no exception is thrown but works fine onLoad event,opens a open save dialog box to save a word file..
string strDocBody;
strDocBody = "<html " + "xmlns:o='urn:schemas-microsoft-com:office:office' " + "xmlns:w='urn:schemas-microsoft-com:office:word'" + "xmlns='http://www.w3.org/TR/REC-html40'>" + "<head>" + "<title>Version and Release Management</title>";
strDocBody = strDocBody + "<!--[if gte mso 9]>" + "<xml>" + "<w:WordDocument>" + "<w:View>Print</w:View>" + "<w:Zoom>100</w:Zoom>" + "<w:DoNotOptimizeForBrowser/>" + "</w:WordDocument>" + "</xml>" + "<![endif]-->";
strDocBody = strDocBody + "<style> #page" + "{size:8.5in 11.0in; mso-first-footer:ff1; mso-footer: f1; mso-header: h1; border:solid navy 2.25pt; padding:24.0pt 24.0pt 24.0pt 24.0pt;" + " margin:0.75in 0.50in 0.75in 0.50in ; " + " mso-header-margin:.5in; " + " mso-footer-margin:.5in; mso-paper-source:0;}" + " div.Section1" + " {page:Section1;}" + "p.MsoFooter, li.MsoFooter, div.MsoFooter{margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; tab-stops:center 3.0in right 6.0in; font-size:12.0pt; font-family:'Arial';}" + "p.MsoHeader, li.MsoHeader, div.MsoHeader {margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; tab-stops:center 3.0in right 6.0in; font-size:12.0pt; font-family:'Arial';}" + "-->" + "</style>" + "</head>";
strDocBody = strDocBody + "<body lang=EN-US style='tab-interval:.5in'>" + "<div class=Section1>" + "<h1>This is my Heading</h1>" + "<h2>This is my Sub Heading</h2>" + "<p style='color:navy;'> This is blue text</p>" + "<p style='font-weight:bold; color:green;'><u> This is green bold underlined text </u></p>" + "<p style='color:red'><I>" + DateTime.Now + "</I></p>" + "<!--[if supportFields]>" + "<div style='mso-element:header' id=h1><p class=MsoHeader><span style='mso-tab-count:4'></span><span style='mso-field-code: PAGE '></span> </p></div>" + "<div style='mso-element:footer' id=f1> " + "<p class=MsoFooter style='border:none;mso-border-bottom-alt:solid windowtext .75pt;padding:0in;mso-padding-alt:0in 0in 1.0pt 0in'><o:p> </o:p></p> " + "Page <span style='mso-field-code: PAGE '><span style='mso-no-proof:yes'>1</span></span> of <span style='mso-field-code: NUMPAGES '></span>" + " <span style='mso-tab-count: 12'> <span style='mso-field-code: DATE '></span> " + " </p></div><![endif]-->" + "</div> </body> </html> ";
//Force this content to be downloaded as a Word document
Response.AddHeader("Content-Type", "application/msword");
Response.AddHeader("Content-disposition", "attachment; filename=TEST.doc");
Response.Charset = "";
Response.Write(strDocBody);
I suppose you are trying to feed the data in strDocBody as a Word file to the user. In order to do that, this data has to be the only thing that web server passes to the browser. That's why it works fine when you put it in your OnLoad event handler. It's not the case when you put it in button click handler.
If you want this behavior on button click, this button has to redirect user to another URL which will send the document data and nothing else.
Create a page specifically for serving document, let it be Document.aspx.
Now, I don't know if you need to perform any additional logic on button click. If not, you can just use LinkButton:
<asp:LinkButton runat="server" ID="docLink" Text="Document"
PostBackUrl="Document.aspx" />
Otherwise, just add redirect call in your onClick handler:
protected void btnButton1_Click(object sender, EventArgs e)
{
// ....
Response.Redirect("Document.aspx");
}
based on my experience, this indeed doesn't work for onClick since the headers has already been sent.
This could be because headers were already posted to the client browser. Try clearing with Response.Clear(), make sure you're not within an Ajax call. Another trick is to open a new page, using a client-side anchor with argument compiled dynamically.
EDIT: of course if you clear your Response, page will be blank after asking the user to download the file. Always keep in mind the stateless synchronous behavior of client-server http communication.
I created a .NET class library in C# and exposed it to COM. It works fine as an in-proc COM server. However I want to use it as an out-proc COM server to have it in a separate process.
To do so I try to create a COM+ application. I created an empty COM+ application and added the classes implemented in the class library into it. When I call CoCreateInstance() to instantiate a class implemented in the library, the COM+ surrogate process encounters an access violation and terminates (crash dump folows).
Are there any special steps needed to be taken to create a class library that can be used as an out-proc COM server under COM+?
The COM+ surrogate process crashes with the following crash dump:
Exception: C0000005
Address: 0x000C1618
Call Stack:
! + 0xC1618
mscorwks!Ordinal79 + 0xE41C
mscorwks!Ordinal79 + 0xE4AD
mscorwks!CoInitializeEE + 0x563F
mscorwks!CoInitializeEE + 0x5672
mscorwks!CoInitializeEE + 0x57F1
mscorwks!CoInitializeCor + 0x210E
mscorwks!CoInitializeCor + 0x48D
mscorwks!Ordinal79 + 0x16D2
mscorwks!ReleaseFusionInterfaces + 0x20B28
COMSVCS! + 0xC29A2
COMSVCS! + 0xC2BDA
COMSVCS!CoCreateStdTrustable + 0xCB10
ole32!CoMarshalInterface + 0x2642
ole32!CoInstall + 0x673
ole32!CoQueryAuthenticationServices + 0x1F44
ole32!CoQueryAuthenticationServices + 0x2862
ole32!CoWaitForMultipleHandles + 0xC267
ole32!CoQueryClientBlanket + 0x16CE
ole32!CoCreateObjectInContext + 0xC8E
ole32!CoInstall + 0x87A
ole32!CoWaitForMultipleHandles + 0x10479
ole32!CoMarshalInterface + 0x2808
ole32!CoGetTreatAsClass + 0xBE7
ole32!CoGetTreatAsClass + 0xB9E
ole32!CoMarshalInterface + 0x28F2
ole32!CoMarshalInterface + 0x2642
COMSVCS!CoCreateStdTrustable + 0x106A4
ole32!CoMarshalInterface + 0x2642
ole32!CoPopServiceDomain + 0x14FE
RPCRT4!CheckVerificationTrailer + 0x70
RPCRT4!NdrStubCall2 + 0x215
RPCRT4!CStdStubBuffer_Invoke + 0x82
ole32!StgGetIFillLockBytesOnFile + 0xFC92
ole32!StgGetIFillLockBytesOnFile + 0xFC3C
ole32!CoRevokeClassObject + 0xA3E
ole32!CoRevokeClassObject + 0x963
ole32!StgGetIFillLockBytesOnFile + 0xF872
ole32!WdtpInterfacePointer_UserMarshal + 0x80E
ole32!StgGetIFillLockBytesOnFile + 0xF792
RPCRT4!NdrGetTypeFlags + 0x1C9
RPCRT4!NdrGetTypeFlags + 0x12E
RPCRT4!NdrGetTypeFlags + 0x5A
RPCRT4!CreateStubFromTypeInfo + 0x2D7
RPCRT4!CreateStubFromTypeInfo + 0x318
RPCRT4!NdrConformantArrayFree + 0x2CB
RPCRT4!NdrConformantArrayFree + 0x20F
RPCRT4!I_RpcBCacheFree + 0x61C
RPCRT4!I_RpcBCacheFree + 0x43E
RPCRT4!I_RpcBCacheFree + 0x604
kernel32!GetModuleFileNameA + 0x1B4
Perhaps going through the ServicedComponent example in this answer will help:
Create Out-Of-Process COM in C#/.Net?
I suggest you take a look at .Net Remoting instead.