Friday, 22 September 2017

Asp.Net C# blank on Chart.SaveImage Saving chart from web give blank image

When export chart in c# using Chart1.SaveImage method , I got white image only.

I used below code to export chart as image , but I got as blank white screen only.

            MemoryStream stream = new MemoryStream();
            Chart1.SaveImage(stream, ChartImageFormat.Jpeg);
            BinaryReader binrayRdr = new BinaryReader(stream);
            byte[] bytes1 = ((MemoryStream)stream).ToArray();
            Response.Clear();
            Response.ContentType = "image/png";
            Response.AddHeader("Content-Disposition", "attachment; filename=HTML.png");
            Response.Buffer = true;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.BinaryWrite(bytes1);
            Response.End();


I found solution for this issue(may not be a right way) this may useful to someone who is struck on this.
I load the chart druing load_chart button click event
here ,
MemoryStream str = new MemoryStream();
Chart1.SaveImage(str);
Session["exportImage"] = str;
we have separate Export button , paste the following code in this event,
byte[] bytes1 = ((MemoryStream)Session["exportImage"]).ToArray();
            Response.Clear();
            Response.ContentType = "image/png";
            Response.AddHeader("Content-Disposition", "attachment; filename=HTML.png");
            Response.Buffer = true;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.BinaryWrite(bytes1);
            Response.End();

Its Working for me.

Tuesday, 19 September 2017

Asp.Net c# export Chart to Image

using System.IO;

protected void btnExport_Click(object sender, EventArgs e)
        {
            MemoryStream stream=new MemoryStream();           
            Chart1.SaveImage(stream, ChartImageFormat.Jpeg);
            BinaryReader binrayRdr = new BinaryReader(stream);
            byte[] bytes = ((MemoryStream)stream).ToArray();
            Response.Clear();
            Response.ContentType = "image/png";
            Response.AddHeader("Content-Disposition", "attachment; filename=HTML.png");
            Response.Buffer = true;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.BinaryWrite(bytes);
            Response.End();
        }

Friday, 24 February 2017

Get column names of measure and dimensions from sql Cube

SELECT [CATALOG_NAME] as [DATABASE],  CUBE_NAME AS [CUBE],[DIMENSION_UNIQUE_NAME] AS [DIMENSION],  HIERARCHY_DISPLAY_FOLDER AS [FOLDER],HIERARCHY_CAPTION AS [DIMENSION ATTRIBUTE],  HIERARCHY_IS_VISIBLE AS [VISIBLE]  FROM $system.MDSchema_hierarchies
WHERE CUBE_NAME  ='data warehouse'AND HIERARCHY_ORIGIN=2

SELECT [CATALOG_NAME] as [DATABASE],  CUBE_NAME AS [CUBE],[MEASUREGROUP_NAME] AS [FOLDER],[MEASURE_CAPTION] AS [MEASURE],[MEASURE_IS_VISIBLE]
FROM $SYSTEM.MDSCHEMA_MEASURES
WHERE CUBE_NAME  ='data warehouse'

Sunday, 18 December 2016

Save multiple charts as Image in C# winforms windows application

This is about how to save charts or control or WindowsForm save as Image

private void copyChartToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            using (MemoryStream ms = new MemoryStream())
            {
               
              
                Rectangle sourceRect = pnlMain.ClientRectangle;
                Size targetSize = new Size(pnlMain.Width,pnlMain.Height);
                using (Bitmap tmp = new Bitmap(sourceRect.Width, sourceRect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    pnlMain.DrawToBitmap(tmp, sourceRect);
                    using (Graphics g = Graphics.FromImage(tmp))
                    {
                        g.DrawImage(tmp, new Rectangle(Point.Empty, targetSize));
                    }
                    Clipboard.SetImage(tmp);
                }
               
            }

        }

  

Monday, 22 December 2014

csv file to DataTable in C#

  private static object GetDataTabletFromCSVFile(string csv_file_path)
        {
            DataTable csvData = new DataTable();

            try
            {

                using (TextFieldParser csvReader = new TextFieldParser(csv_file_path))
                {
                    csvReader.SetDelimiters(new string[] { "," });
                    csvReader.HasFieldsEnclosedInQuotes = true;
                    string[] colFields = csvReader.ReadFields();
                    foreach (string column in colFields)
                    {
                        DataColumn datecolumn = new DataColumn(column);
                        datecolumn.AllowDBNull = true;
                        csvData.Columns.Add(datecolumn);
                    }
                    bool isInvoiceMissed = false, isBaseAmountMissed = false;
                    while (!csvReader.EndOfData)
                    {
                        string[] fieldData = csvReader.ReadFields();

                        if (string.IsNullOrEmpty(fieldData[0].ToString()) || fieldData[0].ToString() == "0")
                            isInvoiceMissed = true;

                        if (string.IsNullOrEmpty(fieldData[21].ToString()))
                            isBaseAmountMissed = true;

                        //Making empty value as null
                        for (int i = 0; i < fieldData.Length; i++)
                        {
                            if (fieldData[i] == "")
                            {
                                fieldData[i] = null;
                            }
                        }
                        csvData.Rows.Add(fieldData);
                    }
                    if (isInvoiceMissed && !isBaseAmountMissed)
                        return 1;//"Invoice is missing in Excel files";
                    else if (!isInvoiceMissed && isBaseAmountMissed)
                        return 2;//"Base amount is missing in Excel files";
                    else if (isInvoiceMissed && isBaseAmountMissed)
                        return 3;
                    else
                        return csvData;
                }
            }
            catch (Exception ex)
            {
            }
            return csvData;
        }

Friday, 28 November 2014

the remote computer requires network level authentication which your computer does not support xp

how to fix windows RDP client

To fix windows 7 or XP SP3 clients do the following


• Configure Network Level Authentication


1. Click Start, click Run, type regedit, and then press ENTER.

2. In the navigation pane, locate and then click the following registry
subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa

3. In the details pane, right-click Security Packages, and then click Modify.

4. In the Value data box, type tspkg. Leave any data that is specific to other SSPs, and then click OK.

5. In the navigation pane, locate and then click the following registry
subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders

6. In the details pane, right-click SecurityProviders, and then click Modify.

7. In the Value data box, type credssp.dll. Leave any data that is specific to other SSPs, and then click OK.

8. Exit Registry Editor.

9. Restart the computer.

http://technet.microsoft.com/en-in/library/cc732713.aspx