Monday, June 9, 2014
How to Prevent Blank Page/white space when a Rectangle is hidden in RDLC
I had a requirement where in I want to hide Rectangle (which had tablix and charts inside it) to show and hide based on query string parameters. The requirement was working fine when it is showing the Rectangle but when the rectangle is hiding it is generating Blank Page.
I searched a lot for a solution and came to know one trick which i would like to share with you .
I took a new Table(Tablix) .
Select the Row of the tablix and apply the same visibility expression on the Row visibility that I have applied on Rectangle .
Now drag the rectangle inside the Table row cell , in which you have applied expression .Thats it...!!!
Now check , it will not render Blank page / white space any more... :-)
Point to Note : One thing that only I have noticed and would like to tell you..First apply the Row visibility Expression and then only drag the Rectangle inside the Row cell of the table. This is because , I wasn't able to select the row , if you dragged the Rectangle first.. If you try to select Row, Rectangle gets selected....
Hope it helps!!!
Thanks ,
Nitin Sharma
Saturday, June 7, 2014
Convert input string to Title case in C#
This post is about how to convert your input string into TITLE case in C#.
Examples:
- Snow
White and the Seven Dwarfs.
- Newcastle
upon Tyne / Brighton on Sea .
- The
DiMaggio Line .
- The
Last of the Mohicans .
You can convert your input string either in C# code or in SQL function (scalar function) :
Convert to Title case in C# :
Friday, February 17, 2012
Add Twitter and Facebook like Social Sites link to ASP.NET WebSite
Clicking on Facebook image opens the below page as a pop up:
Thursday, March 18, 2010
Delete Selected item from XML Node

private voidForm1_Load(object sender,EventArgs e)
{
XmlDocument xDoc = newXmlDocument();
xDoc.Load(@"D:\DocumentsOrder.xml");
for (int i = 0; i <>
{
//Add the innertext of the xml document to the listbox
listBox1.Items.AddRange(newobject[] { xDoc.DocumentElement.ChildNodes[i].InnerText });
}
}
On Delete Button Click event write the following Code:
private voidbutton5_Click(object sender,EventArgs e)
{
XmlDocument xDoc = newXmlDocument();
xDoc.Load(@"D:\DocumentsOrder.xml");
//Add the innertext of the xml document to the listbox
xDoc.DocumentElement.RemoveChild(xDoc.DocumentElement.ChildNodes[listBox1.SelectedIndex]);
FileStream WRITER = newFileStream(@"D:\DocumentsOrder.xml", FileMode.Truncate,FileAccess.Write,FileShare.ReadWrite);
xDoc.Save(WRITER);
//Close the writer filestream
WRITER.Close();
//Form1_Load(new object(), new EventArgs());
}

Friday, March 12, 2010
Upload Word Document using Sharepoint Web Services
All,
using System;
usingSystem.Collections.Generic;
using System.Configuration;
usingSystem.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Collections;
using Microsoft.SharePoint;
using System.Net;
namespace Signals
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}
private voidForm1_Load(objectsender,EventArgs e)
{
GetFiles();
GetFoldersList();
}
private void GetFoldersList()
{
wsLists.Lists spList =newSignals.wsLists.Lists();
spList.Credentials = System.Net.CredentialCache.DefaultCredentials;
stringspUrl=ConfigurationSettings.AppSettings["SPFolders"].ToString();
spList.Url ="http://Win08r2/Signals/_vti_bin/Lists.asmx";
XmlNode listnodes = spList.GetListItems("CoastGuard", null, null, null, null, null,null);
foreach (XmlNode nodeinlistnodes)
{
if (node.Name == "rs:data")
{
for (int i = 0; i <>
{
if (node.ChildNodes[i].Name == "z:row")
{
listView1.Items.Add(node.ChildNodes[i].Attributes["ows_LinkFilename"].Value);
}
}
}
}
}
private void GetFiles()
{
string strPath ="..\\..\\Documents";
DirectoryInfo di =newDirectoryInfo(strPath);
FileInfo[] fi = di.GetFiles();
foreach (FileInfo f in fi)
{
listView2.Items.Add(f.Name);
}
}
privatevoidbutton1_Click(objectsender,EventArgs e)
{
wsLists.Lists spList =newSignals.wsLists.Lists();
spList.Credentials = System.Net.CredentialCache.DefaultCredentials;
spList.Url ="http://Win08r2/_vti_bin/Lists.asmx";
listView1.Items[0].Selected =true;
string DocFileName = "";
foreach (ListViewItem linlistView2.SelectedItems)
{
DocFileName = l.Text.ToString();
}
if (DocFileName != "")
{
if(listView1.CheckedItems.Count > 0)
{
for (int i = 0; i <>
{
WebClient WC =newWebClient();
WC.Credentials =CredentialCache.DefaultCredentials;
WC.UploadData("http://Win08r2/signals/CoastGuard/"+ listView1.CheckedItems[i].Text + "/" + DocFileName, "PUT", StreamFile(@"..\\..\\Documents\" + DocFileName));
}
MessageBox.Show("Files moved successfully");
}
else
{
MessageBox.Show("Please Select At Least One Folder");
}
}
else
{
MessageBox.Show("Please Select a File");
}
}
private byte[] StreamFile(stringfilename)
{
FileStream fs =newFileStream(filename,FileMode.Open,FileAccess.Read);
// Create a byte array of file stream length
byte[] ImageData =newbyte[fs.Length];
//Read block of bytes from stream into the byte array
fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
//Close the File Stream
fs.Close();
return ImageData; //return the byte data
}
privatevoidbutton2_Click(objectsender,EventArgs e)
{
foreach (ListViewItem liinlistView1.Items)
{
li.Checked = true;
}
}
privatevoidbutton3_Click(objectsender,EventArgs e)
{
foreach (ListViewItem liinlistView1.Items)
{
li.Checked = false;
}
}
}
}


Fetch Temp directory of Windows using VBA macros
Adding Images in Word Document using C#.NET
I searched and wrote the code as follows but before that :
Step 1) do add reference to Microsoft Word Object Library.
Step 2) Add using Microsoft.Office.Interop.Word;
using System.IO; namespaces on top.
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 Microsoft.Office.Interop.Word;
using System.IO;
namespace Sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
object missing = System.Reflection.Missing.Value;
object Visible=true;
object start1 = 0;
object end1 = 0;
ApplicationClass WordApp = new ApplicationClass();
Document adoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
Range rng = adoc.Range(ref start1, ref missing);
try
{
foreach (ListViewItem Li in listView1.Items)
{
FileInfo Fi = new FileInfo(Li.Text);
rng.InlineShapes.AddPicture(Fi.ToString(), ref missing, ref missing, ref missing);
}
rng.Font.Name = "Georgia";
rng.InsertAfter("Hello World!");
object filename = @"D:\"+textBox1.Text+".docx"; //Saves in D directory
adoc.SaveAs(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void butBrowse_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
string [] FileNames = openFileDialog1.FileNames;
foreach (string nameOfFile in FileNames)
{
listView1.Items.Add(nameOfFile);
}
}
}
}
Thats it..Now check your directory(here it is D directory)
Below is the Screen Shot:


Wednesday, May 6, 2009
Implement Ajax AutoComplete Extender inside Gridview
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/AutoComplete.asmx" />
Services>
asp:ScriptManager>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
AutoGenerateColumns="False" OnRowEditing="GridView1_RowEditing">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="Age" SortExpression="ID">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text=''>asp:Label>
ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblID" runat="server" Text=''>asp:Label>
EditItemTemplate>
asp:TemplateField>
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text=''>asp:Label>
ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtName" runat="server" Text=''>asp:TextBox>
<ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="txtName"
ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList" MinimumPrefixLength="1" CompletionInterval="10" EnableCaching="true" CompletionSetCount="12" />
EditItemTemplate>
asp:TemplateField>
<asp:TemplateField HeaderText="Location" SortExpression="Location">
<ItemTemplate>
<asp:Label ID="lblLocation" runat="server" Text=''>asp:Label>
ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblLocation" runat="server" Text=''>asp:Label>
EditItemTemplate>
asp:TemplateField>
Columns>
asp:GridView>
public DataTable GetRecords(string strName)
{
string strConn = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@Name", strName);
cmd.CommandText = "Select Name from Emp where Name like '%'+@Name+'%'";
DataSet objDs = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter();
dAdapter.SelectCommand = cmd;
con.Open();
dAdapter.Fill(objDs);
con.Close();
return objDs.Tables[0];
}
[WebMethod]
public string[] GetCompletionList(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
DataTable dt = GetRecords(prefixText);
List<string> items = new List<string>(count);
for (int i = 0; i <>
{
string strName = dt.Rows[i][0].ToString();
items.Add(strName);
}
return items.ToArray();
}
ASPX.CS Code
protected void Page_Load(object sender, EventArgs e)
{
Bind();
}
public void Bind()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConnectionString"].ToString());
conn.Open();
SqlCommand cmd = new SqlCommand("Select * from EMP", conn);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GridView1.DataBind();
}

