Monday, 8 April 2013

ASP.Net:Create RSS Feed | Neha Sharma


Introduction:

This article is about to create RSS feed in asp.net

Procedure:

To create a rss feed follow below steps here:

1.       Add below line in to rss page under the page directive line like below :
<%@ OutputCache Duration="120" VaryByParam="*" %>

2.       Create a table with the field Id,title,description and url and enter some dummy data like :


        3.   Add the below code on page load :


string connectionString = "Data Source=name;Initial Catalog=db name;Integrated Security=True";
DataTable d_t = new DataTable();
SqlConnection conn = new SqlConnection(connectionString);
using (conn)
{
SqlDataAdapter adp = new SqlDataAdapter("SELECT * from tablename", conn);
adp.Fill(d_t);
}

Response.Clear();
Response.ContentType = "text/xml";
XmlTextWriter Text_Writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
Text_Writer.WriteStartDocument();
//Below tags are mandatory rss
Text_Writer.WriteStartElement("rss");
Text_Writer.WriteAttributeString("version", "2.0");
// Channel tag will contain RSS feed details
Text_Writer.WriteStartElement("channel");
Text_Writer.WriteElementString("title", " ASP.NET ");
Text_Writer.WriteElementString("link", "http://nehaprogrammer.blogspot.com");
Text_Writer.WriteElementString("description", " C#.NET,ASP.NET ");
Text_Writer.WriteElementString("copyright", "Copyright 2013 - 2014 nehaprogrammer.blogspot.com. All rights reserved.");
foreach (DataRow oFeedItem in d_t.Rows)
{
Text_Writer.WriteStartElement("item");
Text_Writer.WriteElementString("title", oFeedItem["Title"].ToString());
Text_Writer.WriteElementString("description", oFeedItem["Description"].ToString());
Text_Writer.WriteElementString("link", oFeedItem["URL"].ToString());
Text_Writer.WriteEndElement();
}
Text_Writer.WriteEndElement();
Text_Writer.WriteEndElement();
Text_Writer.WriteEndDocument();
Text_Writer.Flush();
Text_Writer.Close();
Response.End();

}

Save all and view the page in browser. It  ll work perfectly.

Thanks


ASP.Net: Convert aspx page in to Pdf | Neha Sharma



Introduction:

This article is about to export an aspx page in to Pdf file.

Requirement:

The only requirement is to add dll of “ITextSharp” in to the application.

Code:

In code behind add below namespaces:
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Drawing;

Design a page.

Place below code on the button click event to convert aspx page in to pdf .

protected void Button1_Click(object sender, EventArgs e)
    {
        string attachment = "attachment; filename=" + "abc" + ".pdf";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/pdf";
        StringWriter s_tw = new StringWriter();
        HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
        h_textw.AddStyleAttribute("font-size", "7pt");
        h_textw.AddStyleAttribute("color", "Black");
        Panel1.RenderControl(h_textw);//Name of the Panel
        Document doc = new Document();
        doc = new Document(PageSize.A4, 5, 5, 15, 5);
        FontFactory.GetFont("Verdana", 80, iTextSharp.text.Color.RED);
        PdfWriter.GetInstance(doc, Response.OutputStream);
        doc.Open();

        StringReader s_tr = new StringReader(s_tw.ToString());
        HTMLWorker html_worker = new HTMLWorker(doc);
        html_worker.Parse(s_tr);

        doc.Close();
        Response.Write(doc);
    }
public override void VerifyRenderingInServerForm(Control control)
    {


    }

Save all and run an error ll occur like the below image



This error occurs when we render a control in to response. Follow the below point to come out from this error:

Add  EnableEventValidation="false" in the page directive on the source of your page at the top

Now save all and view page in browser when you click on the button to convert apx page in to Pdf it ll 
work.


Thanks

Friday, 5 April 2013

ASP.Net : Resize Fonts | Neha Sharma


Live Demo

Hello everyone!

Today i learned a small but interesting and important task this is how to re-size the font .

Write the below code in to your deault.aspx page.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Resize Fonts</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript">
    $(document).ready(function () {
        var divtxt = $('#f_div');
        // Increase Font Size
        $('#btnincfont').click(function () {
            var curSize = divtxt.css('fontSize');
            var newSize = parseInt(curSize.replace("px", "")) + 1;
            $(divtxt).css("fontSize", newSize + "px");
        });
        // Decrease Font Size
        $('#btndecfont').click(function () {
            var curSize = divtxt.css('fontSize');
            var newSize = parseInt(curSize.replace("px", "")) - 1;
            $(divtxt).css("fontSize", newSize + "px");
        })
    });
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="f_div">
hello this is a test page having test text
    <br />
    just to show you the code demo
to make fonts large and small.
    <br />
    <br />
    Click on &quot;+&quot; symbol to make fonts large or
    <br />
    CLick on &quot;-&quot; symbol to make fonts small.</div><br />
<input type="button" id="btnincfont" value=" + " />
<input type="button" id="btndecfont" value=" - " />
</form>
</body>
</html>

Save all and run this page in browser.


Thanks.

Saturday, 9 March 2013

ASP.Net : Export Gridview in PDF | Neha Sharma



Introduction:

Export your daily report in pdf is daily need for any reporting software or application. The same happened when I was working on a project the project was about to finished but sudden anyhow a requirement came to export whole data/report which is displaying in gridview in to pdf.
I was shocked how to add.. when it’s about to finish, but after many try I got the reply that is here :

Requirement:

The only requirement is to add dll of “ITextSharp”  in to the software  to export  the gridview in pdf.

Code:

In code behind add below name spaces :


using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;


Add a gridview and bind that with the database. Add a button to “export in pdf”.
Double click on the button “export in pdf” and write below code there :

Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=report_grid.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter s_w = new StringWriter();
        HtmlTextWriter h_w = new HtmlTextWriter(s_w);
        gvdetails.AllowPaging = false;
        gvdetails.DataBind();
        gvdetails.RenderControl(h_w);
        gvdetails.HeaderRow.Style.Add("width", "15%");
        gvdetails.HeaderRow.Style.Add("font-size", "10px");
        gvdetails.Style.Add("text-decoration", "none");
        gvdetails.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
        gvdetails.Style.Add("font-size", "8px");
        StringReader sr = new StringReader(s_w.ToString());
        Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();

And add the below override method to override your control because in this case when you click to export gridview in to pdf complier never find your gridview in to the form tag :
public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }

Now save all work and run the code it ll look better.

For any query or need dll you can commment here.

Thanks

Thursday, 7 March 2013

Wishing you all a very Happy Women's Day | Neha Sharma



The funny part of Our society,
Is that we call her Mother INDIA,                        
We grab her in feminine dignity and then               
We rape her in colleges,                                      
We burn her in villages,                                       
We attack her in her streets,                                
We murder her in her apartments,                        
We exploit her in her work places and                  
We leave her to die a thousand deaths every moment.
If she works, she is liberal
if she stays at home she will be abused/tortured,                                    
That's how we perceive our women,                  
Don't women make nice subjects for symposiums, neat commemorative dates. 
Don’t make them Flooring material over whom we walk every day. 
The life is not fast forwarding the movie. 
It's about a thought called your original thought. 
A thought that shrieks each time 
when a teenager raped, 
A thought that weeps
when a widow becomes SATI
A thought with fire, 
Think by thinkers who are sometimes ashamed to be a human.

With care & love on this International Women's Day!

Thanks.

Take care!!

Which Game Engine you should choose | Neha Sharma

Unity3D and Unreal Engine are only 2 Game engine which executes an indispensable position in Game Industry. The choice of the engine must ...