I have a lot of tables with lot of rows and columns which I am trying to export into a pdf on a button click in an asp.net webform. This data looks good in a listview. I used iTextSharp, but I couldn't figure out how to export listview to pdf using iTextSharp. So I used datatable and it didn't look very well with iTextSharp. I came across "Spire.DataExport for .NET" but it doesn't seem to be available freely.
Please let me know what's the best way to export a listview into a pdf in asp.net.
UPDATE:
I tried using wkhtmltopdf from codaxy's github link. But even for a simple html line, the conversion is failing from the c# code. Any help on this will be really appreciated, as I have spent a lot of time on this getting nowhere.
c# code:
PdfConvert.ConvertHtmlToPdf(
new PdfDocument { Html = "<html><h1>test</h1></html>" },
new PdfOutput { OutputFilePath = "inline.pdf" }
);
Error::
Server Error in '/JobCosting' Application.
Html to PDF conversion of '-' failed. Wkhtmltopdf output:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: PdfConvertException: Html to PDF conversion of '-' failed. Wkhtmltopdf output:
Source Error:
Line 292: if (process.ExitCode != 0 && !File.Exists(outputPdfFilePath))
Line 293: {
Line 294: throw new PdfConvertException(String.Format("Html to PDF conversion of '{0}' failed. Wkhtmltopdf output: \r\n{1}", document.Url, error));
Line 295: }
Line 296: }
Use wkhtmltopdf from https://wkhtmltopdf.org/
Make HTML from this list control using RenderControl method, and write it fo file, then run that wkhtmltopdf.exe from net using System.Diagnostics.Process class, then it produce pdf file
More answers here Convert HTML to PDF in .NET
Related
I am trying to convert a FPDF extension to Classic Asp. I have installed FPDF for Classic Asp on our server (please no flame war regarding why we still use classic ASP). It works well for all that I have tried. Now I want to have the functionality of WriteTag.php as posted on GitHub under by CREACION DE HORARIOS.
In converting the php code I run into trouble with foreach(this.PileStyle as xval) in the function code below.
I have no idea where "this.PileStyle" comes from. It is this line that gives trouble, which at this time I can't describe, other than that the browser throws the "500 - Internal server error".
Note: there is more to this function, but the foreach shown in the code below is where the error first shows up. My testing so far involves adding small pieces of code to the "writetag.ext" file until an error shows up. I have worked on being able to get the extension loaded in when my "writetag.asp" file starts, until the error appeared. I have not been able to progress to and functional tests.
I have searched both, the PHP and the Classic ASP libraries for FPDF, and find no occurance of help for Classic ASP in this regard.
Any help, or instructions how to proceed, will be greatly appreciated.
this.FindStyle=function FindStyle(tag, ind) //Inheritance from parent elements
{
tag=trim(tag);
// Family
if(this.TagStyle[tag]["family"]!="")
family=this.TagStyle[tag]["family"];
else
{
foreach(this.PileStyle as val)
{
val=trim(val);
if(this.TagStyle[val]["family"]!="")
{
family=this.TagStyle[val]["family"];
break;
}
}
}
I am getting an error at run time when viewing my ASP.NET page in the browser. I am not getting any build errors however I am getting the following compiler error at runtime:
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: CS1513: } expected
Source Error:
Line 329: #line hidden
Line 330: __output.Write("\r\n\t\t\t</div>\r\n\t\t");
Line 331: }
Line 332:
Line 333: private System.Web.UI.Control __BuildControl__control7() {
Source File: c:\Windows\Microsoft.NET\Framework\v1.1.4322\
Temporary ASP.NET Files\xxxxxxxx\450ffa78\d46d847d\
k1gsz9dj.0.cs Line: 331
I cannot locate any missing } in my source code and this error is occurring in the generated code files that exist in the Temporary ASP.NET Files directory. How can I trace this to the line of code that is actually malformed in my page or user controls on my page?
If the error code related as following:
A variable name same as reserved word then you can rename variable.
A code segment such as:
#model MyModel
{
var appname = #Model.Apps.FirstOrDefault(x => x.ID == Model.SelectedApp);
}
Remove '#' coming before Model.Apps.FirstOrDefault(x => x.ID == Model.SelectedApp)
A code segment or section usage such as:
#section{
<!-- hiiii it's not about an error -->
}
Remove the apostrophe from comment in section.
If it is none of these specific cases you can attempt to locate where the error is generated by applying a source reduction. Delete/cut/comment out pieces of code until you can reliably turn the error off and on. The code that turns the error on is likely the culprit if it is not one of the above situations.
Look in the markup (aspx or ascx) for blocks like:
<% ... some C# code.... { %>
markup(controls, html etc)
<% } %>
Any opened bracket { needs to be closed with another bracket }.
These pages or controls are compiled once by ASP .Net when they are first requested.
Visual Studio doesn't compile aspx or ascx files.
If the project is "Web Site" type, Visual Studio compiles the aspx/ascx files, but if the project is "Web Application" type Visual Studio doesn't "compile" the markup (it does not generate the corresponding classes to the aspx/ascx markup)
On my site, the problem was caused by a block of code that looked like this:
#{
var currentNode = #linkedList.Find(#CurrentPage);
if (#currentNode.Next != null)
{
var next = #currentNode.Next;
<li>
#next.Name
</li>
}
if (#currentNode.Previous != null)
{
var prev = #currentNode.Previous;
<li>
#prev.Name
</li>
}
}
I'm not sure why the problem was caused by the nesting. This may be a bug in the compiler.
I got a similar problem and oculd find it only after a log of trial and error.
The error I made was to add a '#' to variables inside a foreach loop which started with:
#foreach
Well as the error suggests, you are missing a closing curly brace '}'
Have a look at the msdn compiler errors documentation:
http://msdn.microsoft.com/en-us/library/83ht1k63(v=vs.80).aspx
As in the example on MSDN:
// the below will cause CS1513 since namespace is missing '}'
namespace y
{
class x
{
public static void Main()
{
}
}
try to compile it in visual studio. i think it will also show where the exact line of the code that has incomplete curly braces.
compilation error cs1513
hey people hope all is well..
i am trying to create a form in VS using ASP that when upon submitting a form the details will get automatically stored in an xml file which can be accessed later on a chosen file save path
i have 2 files ... "Contact.aspx" and "Contact.aspx.vb"
i have created the form in the "Contact.aspx" and when trying to enter the fields in the "contact.aspx.vb" i keep getting several errors such as for example...
Error 5 'Formatting' is not a member of 'System.Web.UI.WebControls.XmlBuilder'
Error 6 'WriteStartDocument' is not a member of 'System.Web.UI.WebControls.XmlBuilder'.
Error 7 'WriteComment' is not a member of 'System.Web.UI.WebControls.XmlBuilder'.
Error 8 'WriteStartElement' is not a member of 'System.Web.UI.WebControls.XmlBuilder'.
Error 10 'WriteAttributeString' is not a member of 'System.Web.UI.WebControls.XmlBuilder'.
there is like 30 errors in total... im literally stuck out my head been trying for 2 days now and can't grasp what im doing wrong ive tried even some of the tutorials online but loads of errors...
hope some1 can fix this
thank you
It looks like you are trying to use an XMLWriter. The XMLWriter class lives in the System.Xml namespace. Try importing (or using) that and give it another try:
VB:
Imports System.XML
C#:
using System.XML;
Example code:
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = (" ");
using (XmlWriter writer = XmlWriter.Create("books.xml", settings))
{
// Write XML data.
writer.WriteStartElement("book");
writer.WriteElementString("price", "19.95");
writer.WriteEndElement();
writer.Flush();
}
Has anyone ever thought to attempt to modify the default ASP.NET Server error page to provide a link BACK to the error source in Visual Studio?
Consider the following standard error page in ASP.NET:
Server Error in '/myproject'
Application.
Invalid object name 'usp_DoSomething'.
Description: An unhandled exception
occurred during the execution of the
current web request. Please review the
stack trace for more information about
the error and where it originated in
the code.
Exception Details:
System.Data.SqlClient.SqlException:
Invalid object name 'usp_DoSomething'.
Source Error:
Line 4323: cmd.CommandText = "usp_DoSomething";
Line 4324:
Line 4325: using (var dr = cmd.ExecuteReader())
Line 4326: {
Line 4327: if (dr != null)
Source File:
c:\development\myproject\myproject.components\providers\sql\sqldataprovider.cs
Line: 4325
When an error like this is generated, the HTML has the source back to the file the error occurs in and the line number. Has anyone ever written or thought of writing some mechanism to turn the text into a link back to the error in Visual Studio?
I've never seen anything that does it, but it just seems like it would be a helluva nice feature and I think about it in the back of my mind every time an error occurs when I have to manually go find it in the source. It would just be nice to be able to click a link to take me straight there.
Anyone written any, or know of any solutions for this. I use Chrome or Firefox as my browsers of choice, but I'd even consider using IE again if someone found a plugin that did this.
Thanks,
Max
Well, I had been hoping for some means of hacking the error page to turn this:
c:\development\myproject\myproject.components\providers\sql\sqldataprovider.cs Line: 4325
into a link back into my source code in Visual Studio... being that the file name and line number is provided. I was thinking of a browser plugin or something, but apparently no one has built anything like that before... oh well. Was worth a shot.
I used something like
Dim i As String
i = Server.MapPath("~/photos/") + fileName
Only once in a project that was working and online, on the offline version, when I run it on my machine, its working, no errors, I uploaded it, it gave me an error like:
'~/photos/http://www.MyURL.com/photos/4411568359267Pic003.jpg' is not a valid virtual path.
Indicating a line in my code:
var marker = new GMarker(new GLatLng(<%=coordinates%>));
This have never happened before, and I don't know where to start troubleshooting as this script -Google Maps- doesn't even need images, i tried to comment it out, it gave me the same error but on a different script this time, the one that show formatting toolbar for the text areas
Line 8: new nicEditor({buttonList : ['fontSize','fontFamily','fontFormat','bold','italic','underline','strikethrough','forecolor','bgcolor','removeformat'], iconsPath : '../nicEdit/nicEditorIcons.gif'}).panelInstance('<%= txtDescription.ClientID %>');
..please HELP :'(
can you post your fileupload aspx page and your function so we can troubleshoot it.
"'~/photos/http://www.MyURL.com/photos/4411568359267Pic003.jpg'"
look closely at the url, it is tacking the full url on to "i". what type of control or you using, a generic or a server side control
solved, turns out the error is due to old database records when i was storing the whole path in the fileName...Thanks Joshua and Keltex