Tuesday, November 12, 2013

Open and Save As Dialog Boxes / Propmt Dialog Box

Here i have posted code for download and open dialog code using Asp.net with C#.
if u have already created file or open file using this code, and client can save and download file
using this.
  
 Response.Clear();
 Response.ContentType = "application/pdf";
 Response.AppendHeader("Content-Disposition", "attachment; filename=yourfilename.pdf");
 Response.TransmitFile(Server.MapPath("~/DirectoryName/yourfilename.pdf"));
Hey gusys, here you can add ContentType as per your file format. Note:Don't use blank space between your file name.

Friday, October 18, 2013

How To Create Html To Pdf In Asp.net Using ITexhsharp

This Code Is useful to you for Create Html to pdf using ITextsharp library(5.4.1.0).

ITextSharp Liberary you can Download From nugetPackage also.

Here, I describe How to down load yor Html Page and Convert to Pdf.
  
public void ConvertHTMLToPDF()
{
    string HTMLCode = new WebClient().DownloadString("Your Page Url");//Here you add your page url.
    string filePath = Server.MapPath("~") + "/App_Data/" + DateTime.Now.Ticks + ".pdf";

    System.IO.StringWriter stringWrite = new StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

    StringReader reader = new StringReader(HTMLCode);
    Document doc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);

    HTMLWorker parser = new HTMLWorker(doc);

    PdfWriter.GetInstance(doc, new FileStream(filePath, FileMode.Create));
    doc.Open();

    try
    {
        parser.Parse(reader);
    }
    catch (Exception ex)
    {
        //Print Error In You Pdf File
        Paragraph paragraph = new Paragraph("Error!" + ex.Message);
        Chunk text = paragraph.Chunks[0] as Chunk;
        if (text != null)
        {
            text.Font.Color = BaseColor.RED;
        }
        doc.Add(paragraph);
    }
    finally
    {
        doc.Close();
    }
}
Note: SomeTime this code not working whenever you are using inline stylesheet or inline stylesheet in your code.


Thursday, August 22, 2013

Editable Grid

Add Javascript In Your Code.
  

    
Add HTML code In your aspx.page.
  

    
    
    
ProductID Name Qnt Price Total
      Total 0.00