Wednesday, 31 October 2012

Step by Step Creation of .rdlc report in Asp.net with c#

Step by Step Creation of  .rdlc report in Asp.net with c#


Step 1 : Create a Query and get the data from your database ..

Step 2: Add DataSet Item 
        2.1 Right click on your website and select ADD NEW ITEM option
        2.2 Select DataSet.xsd and give the name .... view below image and add one table same as your query is giving result ...



Step 3: After adding table you have to add the .rdlc report to your project 
        3.1 Right click on your website and select ADD NEW ITEM option
        3.2 Select Report.rdlc and give the name .... view below image and add one table same as your query.
        3.3 One Report page is Appear Right click on the Report page and select Insert and then Table option

 
        
   3.4 Just add fields to table 
Step 4: After that just you have to call the report by using your .aspx page ...

Step 5 :  


Create one .aspx Page 

//-------------------

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

Page" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <rsweb:reportviewer id="RptViewer" runat="server" font-names="Verdana" font-size="8pt"
        height="800px" interactivedeviceinfos="(Collection)" waitmessagefont-names="Verdana"
        waitmessagefont-size="14pt" width="900px">
                <LocalReport ReportPath="Report\Reseller\RdlcFile\rptResellerAccountingInfo.rdlc">
                    <DataSources>
                        <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
                    </DataSources>
                </LocalReport>
            </rsweb:reportviewer>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="DataSet1TableAdapters.">
    </asp:ObjectDataSource>
    </form>
</body>
</html>



//-------------------

using Microsoft.Reporting.WebForms;


put this code in your function to load reportViewer 
DataSet ds = new DataSet();
ds = //------------------Fill this database by your code
ReportDataSource rds = new ReportDataSource("DataSet1", ds.Tables[0]);
RptViewer.LocalReport.DataSources.Clear();
RptViewer.LocalReport.DataSources.Add(rds);
RptViewer.LocalReport.Refresh();


//-----------------------------------

How to handle large size Query string on server C#


How to handle large size Query string on server C#

Put this code in Web.config file


<configuration>
 <system.web>
  <httpRuntime maxQueryStringLength="10000" />
 <system.web>

<configuration>


How to handle Browser back button using c#

How to handle Browser back button using Asp.net c# on

Step 1 : Put this code on page ,where you don't back to come back by using back button...


 protected override void OnPreRender(EventArgs e)
    {
        ViewState["PreviousPage"] = Request.UrlReferrer;
        base.OnPreRender(e);
        string strDisAbleBackButton;
        strDisAbleBackButton = "<script language='javascript'>\n";
        strDisAbleBackButton += "window.history.forward(-1);\n";
        //   strDisAbleBackButton += "alert('" + ViewState["PreviousPage"].ToString()+ "');\n";
        strDisAbleBackButton += "\n</script>";
        ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "clientScript", strDisAbleBackButton);
        // Response.Redirect("~/Login.aspx");
    }


Example :-

Your first page is FirstPage.aspx   -----Note: - Put code in this page
Your Second Page is : - SecondPage.aspx

and when you redirect from firstpage.aspx to secondpage.aspx page and press back button that time the Page FirstPage.aspx will not allow the redirect ....

Open asp.net and run page in SSL mode using C#

How to force http to https using c# code



using System.Web;

    public static void setSecureProtocol(bool bSecure)
    {
        string redirectUrl = null;
        HttpContext context = HttpContext.Current;
        if (bSecure && !context.Request.IsSecureConnection)
            redirectUrl = context.Request.Url.ToString().Replace("http:", "https:");
        if (redirectUrl != null)
            context.Response.Redirect(redirectUrl);
    }



 protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                setSecureProtocol(true);             
            }
        }
        finally
        {

        }

    }



Email sending code in Asp.net c# for your Web Server Email Address

Email sending code in Asp.net c# for your Web Server Email Address  


public Boolean sendEmail(string message, string toEmailAddress, string subject, string title)
    {
        try
        {

            NetworkCredential loginInfo = new NetworkCredential("user@website.com", "password");
            System.Net.Mail.MailMessage msg = new MailMessage();
            msg.From = new MailAddress("user@website.com", "Title");
            msg.To.Add(new MailAddress(toEmailAddress));
            msg.Subject = subject;
            msg.Body =message;
            msg.IsBodyHtml = true;
            SmtpClient client = new SmtpClient("mailserverAddress"); ex:- webmail.WebsiteName.com
            client.UseDefaultCredentials = false;
            client.Credentials = loginInfo;
            client.Send(msg);
            msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
            string x = DeliveryNotificationOptions.OnSuccess.ToString();
            return true;
        }
        finally
        {

        }
    }

Set Asp.net Default Page In Web.config file

How to set default page setting in Asp.net Web.config file



 <system.webServer>
    <defaultDocument>
      <files>
        <clear />
        <add value="PageName.aspx" />
      </files>
    </defaultDocument>
 </system.webServer>

Tuesday, 30 October 2012

How to set Custom Error handling in Asp.net Web.config

How to set custom error handling in Web.config file Asp.net




<configuration>
<system.web>
 <customErrors mode="RemoteOnly" defaultRedirect="~/Errors/DefaultErrorPage.aspx">
      <error statusCode="400" redirect="~/Errors/ErrorPage400.aspx" />
      <error statusCode="401" redirect="~/Errors/ErrorPage401.aspx" />
      <error statusCode="403" redirect="~/Errors/ErrorPage403.aspx" />
      <error statusCode="404" redirect="~/Errors/ErrorPage404.aspx" />
      <error statusCode="405" redirect="~/Errors/ErrorPage405.aspx" />
........................Specify more error code
    </customErrors>
</system.web>
</configuration>

Wednesday, 26 September 2012

Asp.net C# - Database acces

Database Layer - This demo will help you to access database secure and save your time in coding and testing.