Tuesday, 25 September 2012

How to add chart control in sharepoint

Step1:
Download chart control  from the following link (Click here)
download another exe file (Click here to download)

step2:
Make changes as follows in web.config(so that only chart control will appear)

<pages>
<controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.Datavisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </controls>
</pages>
 
<httpHandlers>
 <add path="ChartImg.axd" verb="GET, HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
</httpHandlers>
 
<appSettings>
 <add key="ChartImageHandler" value="Storage=memory;Timeout=180;Url=~/tempImages/;" />
</appSettings>
 
<handlers>
 <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </handlers>


Step3:
go to "C:\Program Files (x86)\Microsoft Chart Controls\Assemblies\System.Web.DataVisualization.Design.dll"
add this dll reference to our visual studio solution.
and also add"System.Web.DataVisualization.Design.Dll"


Step4:
go to toolbox add new tab->chooseitems->click browse->Add dll which is mensioned above-->add Chart control

Step5:
if any error comes assembly not found means " in your solution find packages click it -->Advanced-->Add->Choose dll from path where we have stored that dll(incase problem comes)

Step 6:
drag and drop the chart control in visual webpart (now it will show "object reference not set to an instatnce of variable" no problem with this.
in code behind paste the following code


protected void Page_Load(object sender, EventArgs e)
        {



 string[] x = new string[4] { "Mango", "Apple", "Orange", "Banana" };
            int[] y = new int[4] { 200, 112, 55, 96 };
            Chart1.Series[0].Points.DataBindXY(x, y);
            Chart1.Series[0].ChartType = SeriesChartType.Bar;
            Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
}

this will show chart control in visual web part for asp.net we no need to change the web.config file







Step6:Export Chart control to pdf
before that add these two dll as reference
itextsharp.dll
itextsharp.pdfa.dll

paste this code in button click event


protected void btnsubmit_Click(object sender, EventArgs e)
        {
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            using (MemoryStream stream = new MemoryStream())
            {
                Chart1.SaveImage(stream, ChartImageFormat.Png);
                iTextSharp.text.Image chartImage = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
                chartImage.ScalePercent(75f);
                pdfDoc.Add(chartImage);
                pdfDoc.Close();
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment;filename=Chart.pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.Write(pdfDoc);
                Response.End();
            }
        }


















Export to excel Code






protected override void Render(HtmlTextWriter writer)
        {
            if (Page != null)
            {
                if (bexport)
                {
                    grdshow.Visible = true;
                    this.bexport = false;
                    Page.Response.Clear();
                    Page.Response.Buffer = true;
                    Page.Response.ContentType = "application/ms-excel";
                    Page.Response.AddHeader("content-disposition", "attachment; filename=Excelsheetname" + DateTime.Now + ".xls");
                    Page.Response.Charset = "UTF-8";
                    DateTime ct = DateTime.Now;
                    string currentdate = Convert.ToString(ct);
                    HttpContext.Current.Response.Write("

Excelsheetname

");                    this.EnableViewState = false;
                    System.IO.StringWriter sw = new System.IO.StringWriter();
                    System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
                    grdshow.RenderControl(htw);
                    Page.Response.Write(sw.ToString() + "

Report Date : " + currentdate + "");
                    Page.Response.End();
                }
            }
            base.Render(writer);
        }



  protected void btnexport_Click(object sender, EventArgs e)
        {
            this.bexport = true;

        }

Marquee with Border







"tag start"
marquee style="position: relative; top: 0px; left: 0px;" behavior="scroll" align="center"

                                                                height="210px" direction="up" scrollamount="2" scrolldelay="5" onmouseover="this.stop()"
                                                                onmouseout="this.start()"  
                                                                       "tagclose"
                                                                Text1
                                                               
                                                               Text2
                                                               
                                                          "tagstart"  marquee "tag close"





          in marquee text like this"< "marquee"tagstart tagclose" 


How to assign itemcollection  for textbox


SPListItemCollection oitemcoll = olist.GetItems(orydet);
                        if (oitemcoll.Count > 0)
                        {
                            drpnmofp.DataSource = oitemcoll.GetDataTable();
                            drpnmofp.DataTextField = "Title";
                            drpnmofp.DataValueField = "Title";
                            drpnmofp.DataBind();
                        }

Friday, 14 September 2012

 Textbox auto complete in windows application



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;


namespace WindowsForm_Autocomplete
{
    public partial class Form1 : Form
    {
        

        AutoCompleteStringCollection namesCollection =new AutoCompleteStringCollection();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                 SqlDataReader dReader;
                SqlConnection conn = new SqlConnection(@"Data Source=IGRID103\SHAREPOINT;Initial Catalog=Multilingual;Integrated Security=True");
                //conn.ConnectionString = strConnection;
                SqlCommand cmd = new SqlCommand("Select distinct [English] from [Languages] order by [English] asc", conn);
                conn.Open();
                dReader = cmd.ExecuteReader();
                if (dReader.HasRows == true)
                {
                    while (dReader.Read())
                        namesCollection.Add(dReader["English"].ToString());
                }
                else
                {
                    MessageBox.Show("Data not found");
                }
                dReader.Close();
                textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
                textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
                textBox1.AutoCompleteCustomSource = namesCollection;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }



        }
    }
}

Result





   Create store procedure
create table tablename(English nvarchar(max),Tamil nvarchar(max),Hindi nvarchar(max))




create procedure procedurename(@name nvarchar(max),@tami nvarchar(max),@hindi nvarchar(max))
as
begin
insert into tablename values(@name,@tami,@hindi)
end
 exec languagepro N'Address' ,N'முகவரி',N'पता'