Wednesday, August 8, 2012

Overflow hidden on table - displaying without scroll bar

<table style="width:50%;table-layout:fixed;">
<tr>
<td style="overflow:hidden;white-space:nowrap;">The Writing Life: The point of the long and winding sentence The Writing Life: The point of the long and winding sentence</td>
</tr>
</table>

Remove all special characeter in String.


Remove all special characeter in String.
string title = "You, should be <careful. with , (your current approach) ";
title = Regex.Replace(title, "[^0-9a-zA-Z]+", " ");

Output:
You should be careful with your current approach

Regex.Replace(title, "[^0-9a-zA-Z]+", ""); -- also Remove Space.

Output:
Youshouldbecarefulwithyourcurrentapproach

Monday, July 30, 2012

IE text-decoration with images issues

<style type="text/css">
img{
border:0px;
}
img a, img a:link, img a:active, img a:visited, img a:hover{
border:0px;
}
</style>

Monday, February 20, 2012

Removing duplicates from a collection

List list = new List();
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(3);
list.Add(4);
list.Add(4);
List distinct = list.Distinct().ToList();

Wednesday, January 18, 2012

Using multiple data reader

To use multiple data reader objects add MultipleActiveResultSets="True" with in the connection string.

Monday, November 21, 2011

Running PowerShell script from C#

To run the PowerShell scripts from C# add a reference to System.Management.Automation assembly and include the following namespaces

using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

private string RunScript(string scriptText)
{
    Runspace runspace = RunspaceFactory.CreateRunspace();
    runspace.Open();
    Pipeline pipeline = runspace.CreatePipeline();
    pipeline.Commands.AddScript(scriptText);
    pipeline.Commands.Add("Out-String");
    Collection results = pipeline.Invoke();
    runspace.Close();
    StringBuilder stringBuilder = new StringBuilder();
    foreach (PSObject obj in results)
    {
        stringBuilder.AppendLine(obj.ToString());
    }
    return stringBuilder.ToString();
}

Friday, November 18, 2011

Export GridView in ASP.NET to excel

protected void btnExport_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ExportFile.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
gvReport.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}