tag:blogger.com,1999:blog-9605657722703613272024-03-13T03:03:54.075-07:00Dot Net Experts BlogDot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-960565772270361327.post-86240529241298509842015-01-27T22:43:00.000-08:002015-01-27T23:09:24.997-08:00All date related solution<div dir="ltr" style="text-align: left;" trbidi="on">
All date related solution<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
if (!IsPostBack)<br />
{<br />
GetnextSunday();<br />
<br />
for (int i = 1; i <= 31; i++)<br />
{<br />
DateTime start = new DateTime(2015, 1, i);<br />
DateTime stop = new DateTime(2015, 1, 31);<br />
<br />
int totalWorkingDays = GetNumberOfWorkingDays(start, stop);<br />
<br />
Console.WriteLine("There are {1} working days from Oct {0}, 2014 to Oct 31, 2014.", i, totalWorkingDays);<br />
}<br />
DateTime start1 = new DateTime(2015, 1, 1);<br />
DateTime stop1 = new DateTime(2015, 1, 31);<br />
int cntcoun = CountDays(start1, stop1);<br />
GetAllSundays(start1, stop1);<br />
}<br />
}<br />
public void GetnextSunday()<br />
{<br />
var date = DateTime.Now;<br />
var nextSunday1 = date.AddDays(7 - (int)date.DayOfWeek);<br />
<br />
DateTime d = DateTime.Today;<br />
<br />
int offset = d.DayOfWeek - DayOfWeek.Monday;<br />
<br />
DateTime lastMonday = d.AddDays(-offset);<br />
DateTime nextSunday = lastMonday.AddDays(6);<br />
}<br />
private static int GetNumberOfWorkingDays(DateTime start, DateTime stop)<br />
{<br />
TimeSpan interval = stop - start;<br />
<br />
int totalWeek = interval.Days / 7;<br />
int totalWorkingDays = 5 * totalWeek;<br />
<br />
int remainingDays = interval.Days % 7;<br />
<br />
<br />
for (int i = 1; i <= remainingDays; i++)<br />
{<br />
DayOfWeek test = (DayOfWeek)(((int)start.DayOfWeek) % 7);<br />
if (test >= DayOfWeek.Monday && test <= DayOfWeek.Friday)<br />
totalWorkingDays++;<br />
}<br />
<br />
return totalWorkingDays;<br />
}<br />
<br />
public int CountDays(DateTime fromDate, DateTime toDate)<br />
{<br />
int noOfDays = 0;<br />
DateTime fDate = Convert.ToDateTime(fromDate);<br />
DateTime tDate = Convert.ToDateTime(toDate);<br />
while (DateTime.Compare(fDate, tDate) <= 0)<br />
{<br />
if (fDate.DayOfWeek != DayOfWeek.Saturday && fDate.DayOfWeek != DayOfWeek.Sunday)<br />
{<br />
noOfDays += 1;<br />
}<br />
fDate = fDate.AddDays(1);<br />
}<br />
return noOfDays;<br />
}<br />
public void GetAllSundays(DateTime Date1, DateTime Date2)<br />
{<br />
TimeSpan DateDiff = Date2.Subtract(Date1);<br />
List<DateTime> lstdate = new List<DateTime>();<br />
for (int i = 0; i <= DateDiff.Days; i++)<br />
{<br />
if (Date1.Date.AddDays(i).DayOfWeek == DayOfWeek.Sunday)<br />
{<br />
lstdate.Add(Date1.Date.AddDays(i));<br />
}<br />
}<br />
}</div>
Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com0tag:blogger.com,1999:blog-960565772270361327.post-74249735820805584842015-01-27T22:30:00.000-08:002015-01-28T00:24:54.806-08:00how to do sorting on gridview<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
private void BindGrid()<br /> {<br /> if (ViewState["SortExp"] != null && ViewState["order"] != null)<br /> {<br /> lstemp.Sort(new GenericComparer<Employee>(ViewState["SortExp"].ToString(), (SortDirection)ViewState["order"]));<br /> }<br /> GridView1.DataSource = lstemp;<br /> GridView1.DataBind();<br /><br /> }<br /> SortDirection sortOrder;<br /> protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)<br /> {<br /> try<br /> {<br /> if (ViewState["SortExp"] != null && ViewState["SortExp"].ToString().ToLower() == e.SortExpression.ToString().ToLower()<br /> && ViewState["order"] != null && (SortDirection)ViewState["order"] == SortDirection.Ascending)<br /> {<br /> sortOrder = SortDirection.Descending;<br /> }<br /> else<br /> {<br /> sortOrder = SortDirection.Ascending;<br /> }<br /><br /> ViewState["order"] = sortOrder;<br /> ViewState["SortExp"] = e.SortExpression;<br /> this.BindGrid();<br /> }<br /> catch (Exception ex)<br /> {<br /> <br /> }<br /> }<br />
<br />
create new class<br />
<br />
public class GenericComparer<T> : IComparer<T><br /> {<br /> /// <summary><br /> /// Define sort direction Ascending or descending<br /> /// </summary><br /> private SortDirection sortDirection;<br /><br /> /// <summary><br /> /// Gets or sets the sort direction.<br /> /// </summary><br /> /// <value>The sort direction.</value><br /> /// <remarks></remarks><br /> public SortDirection SortDirection<br /> {<br /> get { return this.sortDirection; }<br /> set { this.sortDirection = value; }<br /> }<br /><br /> /// <summary><br /> /// Define the name in which data is to be sort.<br /> /// </summary><br /> private string sortExpression;<br /><br /> /// <summary><br /> /// Initializes a new instance of the <see cref="GenericComparer&lt;T&gt;"/> class.<br /> /// </summary><br /> /// <param name="sortExpression">The sort expression.</param><br /> /// <param name="sortDirection">The sort direction.</param><br /> /// <remarks></remarks><br /> public GenericComparer(string sortExpression, SortDirection sortDirection)<br /> {<br /> this.sortExpression = sortExpression;<br /> this.sortDirection = sortDirection;<br /> }<br /> public int Compare(T x, T y)<br /> {<br /> PropertyInfo propertyInfo = typeof(T).GetProperty(sortExpression);<br /> IComparable obj1 = (IComparable)propertyInfo.GetValue(x, null);<br /> IComparable obj2 = (IComparable)propertyInfo.GetValue(y, null);<br /><br /> if (obj1 == null)<br /> {<br /> if (SortDirection == SortDirection.Ascending)<br /> {<br /> return (obj2 == null) ? 0 : -1;<br /> }<br /> else<br /> {<br /> return (obj2 == null) ? -1 : 0;<br /> }<br /> }<br /> if (obj2 == null) { return 1; }<br /><br /> if (SortDirection == SortDirection.Ascending)<br /> {<br /> return obj1.CompareTo(obj2);<br /> }<br /> else return obj2.CompareTo(obj1);<br /> }<br /> <br /> }</div>
Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com0tag:blogger.com,1999:blog-960565772270361327.post-38306188338539713022012-06-26T10:33:00.000-07:002012-06-26T10:33:01.516-07:00Example on Windows Service Wothout Setup<div dir="ltr" style="text-align: left;" trbidi="on">
Hi Friends,in this post i would like to explain windows service for displaying message box for every 3 seconds.<br /><br />Step 1:<br /><br />* Open windows service project with projectName WinService1<br />* Goto ToolBox-->General-->Right Click-->Select choose items-->Select Timer(Systems.Timers)<br />* Project-->AddReference-->System.Windows.Forms(Message Box is a part of above reference).<br />* Place a Timer(System.Timers) with interval-3000 & enabled-false.<br /><br />Code:<br /><br />{//timer1_Elapsed event.<br />System.Windows.Forms.MessageBox.Show("This message from Windows Service.");<br />}<br /><br />Code for OnStart() event<br />{<br />timer1.Enabled=true;<br />}<br /><br />Code for OnStop() event<br />{<br />timer1.Enabled=false;<br />}<br /><br /><br />Step 2:<br /><br />* Open service1.cs[design]<br />Right Click<br />Add installer(Select).<br />Then 2 controls will be added to the form.<br />1)ServiceProcessInstaller-->Choose properties-->Account=LocalSystem.<br />2)ServiceInstaller-->Properties-->ServiceName=MessageBoxDisplay<br /><br />* Build the project(Build-->Select Build solution)<br /><br />Note:<br />* WinService1.exe is created under:<br />D:\WinService1\bin\debug folder with a service name called as "MessageBoxDisplay"<br /><br />Step 3:<br /><br />* open .Net Command prompt.<br />Start-->Programs-->MSVisualStudio2005-->VSTools-->.Net Command Prompt.<br />>installutil -i D:\WinService1\bin\debug\WinService1.exe (press enter)<br />>....<br />>....<br />>....<br />>transaction install has completed.<br /><br />Step 4:<br /><br />* Open service(Start-->run-->services.msc)<br />* MessageBoxDisplay-->RightClick-->Properties-->Logon-->Check "interact with desktop" checkBox-->OK<br />(Only service contains MessageBox otherwise above step is not required).<br />* MessageBoxDisplay-->rightClick-->Start.<br /><br />Then service will be started & MessageBox with message(This message from Windows Service.) will be displayed for every 3 seconds.<br /><br /><br />Thank You...</div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com0tag:blogger.com,1999:blog-960565772270361327.post-26478091219499187002012-06-26T10:00:00.001-07:002012-06-26T10:00:07.120-07:00What Is Delegate with a simple example<div dir="ltr" style="text-align: left;" trbidi="on">
aIntroduction<br />
This article is an attempt to explain a delegate with a simple example. Delegates
are similar to function pointers in C++. For simple understanding delegates can
be defiend as methods that are used to call other method. Only condition to call
<br />
<br />
another method from a delegate is that the signature of the calling methods and
delegates should match.<br />
Follw This Step<br />
Delegates should have the same signature as the methods to be called by them.
<br />
i.e. Say that we are calling an addNumbers method which returns an integer by taking
(int, int) as input. Then our
<br />
<br />
delegate also must have been declared with the same signature.
<br />
Delegate Declaration:<br />
public delegate int simpleDelegate (int a, int b);
<br />
<br />
Method:<br />
public int addNumber(int a, int b)
<br />
Step For Create And Cal A Delegate<br />
--Create a delegate. A delegate can be created with the delegate keyword, followed
by it's return type, then name of the
<br />
<br />
delegate with the input patameters.<br />
<br />
public delegate int simpleDelegate (int a, int b);
<br />
<br />
--Define the methods which are having similar signature as the delegate.<br />
<br />
<div id="Div1" name="tbl2" style="background-color: #ccccff; border: 0.02em solid Black; display: block; overflow: hidden; width: 600px;">
public int mulNumber(int a, int b)<br />
public int addNumber(int a, int b)</div>
--Now we are all set to use the delegates. Just instatiate the class and call the
methods using the delegates.<br />
Code Use<br />
<div id="tbl2" name="tbl2" style="background-color: #ccccff; border: 0.02em solid Black; display: block; overflow: hidden; width: 600px;">
class clsDelegate<br />
{<br />
public delegate int simpleDelegate (int a, int b);
<br />
public int addNumber(int a, int b)<br />
{<br />
return (a+b);<br />
}<br />
public int mulNumber(int a, int b)<br />
{<br />
return (a*b);<br />
}<br />
static void Main(string[] args)<br />
{<br />
clsDelegate RAPatel = new clsDelegate();<br />
simpleDelegate addDelegate = new simpleDelegate(RAPatel.addNumber);<br />
simpleDelegate mulDelegate = new simpleDelegate(RAPatel.mulNumber);<br />
int addAns = addDelegate(10,12);<br />
int mulAns = mulDelegate(10,10);<br />
Console.WriteLine("Result by calling the addNum method using a delegate: {0}",addAns);<br />
Console.WriteLine("Result by calling the mulNum method using a delegate: {0}",mulAns);<br />
Console.Read();<br />
}<br />
}</div>
</div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com0tag:blogger.com,1999:blog-960565772270361327.post-2178517990646547262012-06-26T09:32:00.000-07:002012-06-26T09:32:05.086-07:00How to Create Setup File And how to install,Start windows service<div dir="ltr" style="text-align: left;" trbidi="on">
aaa<br />
<strong>Introduction: </strong><br /><br />Here I will explain how to install windows service and how to start the windows service in our local machine.<br /><br /><strong>Description: </strong><br /><br /> In previous article I explained clearly how to Create Setup File and how to run windows service in scheduled intervals. Now I will explain how to install windows service in our system.<br /><br />To install windows service in your follow these steps<br /><br /><strong>Step-1</strong><br /> Create New Project- Select Setup- And Give Setup File Name…….<br />
<br />
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIVPTsV89sPMOVvUHHQ4asgwa9OQkHmfE6Wwgx4iyDQ29DSoUOOQUjn-viZ16lGOoFOh1blnkGY5Uz4qJNLDKq5mtnLLvAt60I95-31_Jzxsha2JbarWFRvqRRM18CKlj2Cmhi3VjkpLv-/s1600/Setup11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIVPTsV89sPMOVvUHHQ4asgwa9OQkHmfE6Wwgx4iyDQ29DSoUOOQUjn-viZ16lGOoFOh1blnkGY5Uz4qJNLDKq5mtnLLvAt60I95-31_Jzxsha2JbarWFRvqRRM18CKlj2Cmhi3VjkpLv-/s400/Setup11.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Step-2<br /> First Bind Both Project..<br /> And Install your Setup File..</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix0KS8Vh2_1MiKWYfC_624I1_0J8XKHxVXJpF3qYEMklc3QYc5C_D56_FfwpV7qUGzr68FhzA3XlFjV1pEHVx6KUFxJGe1k-9fTXEF7DDN_7nl0ho5rEv9mXAe-UMcZxoGYg2uz_nTD-DM/s1600/Setup33.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix0KS8Vh2_1MiKWYfC_624I1_0J8XKHxVXJpF3qYEMklc3QYc5C_D56_FfwpV7qUGzr68FhzA3XlFjV1pEHVx6KUFxJGe1k-9fTXEF7DDN_7nl0ho5rEv9mXAe-UMcZxoGYg2uz_nTD-DM/s400/Setup33.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Step-3<br /> Open Services And Start Our ScheduledService Service……</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix0KS8Vh2_1MiKWYfC_624I1_0J8XKHxVXJpF3qYEMklc3QYc5C_D56_FfwpV7qUGzr68FhzA3XlFjV1pEHVx6KUFxJGe1k-9fTXEF7DDN_7nl0ho5rEv9mXAe-UMcZxoGYg2uz_nTD-DM/s1600/Setup33.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix0KS8Vh2_1MiKWYfC_624I1_0J8XKHxVXJpF3qYEMklc3QYc5C_D56_FfwpV7qUGzr68FhzA3XlFjV1pEHVx6KUFxJGe1k-9fTXEF7DDN_7nl0ho5rEv9mXAe-UMcZxoGYg2uz_nTD-DM/s400/Setup33.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br /></div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com0tag:blogger.com,1999:blog-960565772270361327.post-49531508655553492042012-06-25T02:26:00.002-07:002012-06-29T04:05:13.804-07:00Moveable Telerik Rad window in WPF<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;">
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: "Verdana","sans-serif";">Introduction :</span></b></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Verdana","sans-serif";">How to Move Telerik Rad Window in WPF</span><br />
<span lang="EN-US" style="font-family: "Verdana","sans-serif";"><br /></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: "Verdana","sans-serif";">Descritption :</span></b></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Verdana","sans-serif";">You can move your rad window move any where in your
page</span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: "Verdana","sans-serif";"><br /></span></b><br />
<b><span lang="EN-US" style="font-family: "Verdana","sans-serif";">Using Code :</span></b></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: "Verdana","sans-serif";">In
Design View :</span></b><br />
<b><span lang="EN-US" style="font-family: "Verdana","sans-serif";">
<div id="tbl3" name="tbl3" style="background-color: #ccccff; border: 0.02em solid Black; display: none; overflow: hidden; width: 600px;">
<Canvas Name="mycanvas" Height="{Binding Height,ElementName=radWindow2}" Width="{Binding Width,ElementName=radWindow2}" ><br />
<Thumb DragDelta="Thumb_DragDelta" Height="20" Canvas.Top="0" Canvas.Left="0" Panel.ZIndex="2" Name="thumbh1" Visibility="{Binding Visibility,ElementName=radWindow2,Mode=TwoWay}" Width="243" MouseEnter="thumbh1_MouseEnter" MouseLeave="thumbh1_MouseLeave" Background="Transparent" > <br />
<Thumb.Template><br />
<ControlTemplate> <br />
<TextBlock Text="" Background="Transparent"></TextBlock> <br />
</ControlTemplate><br />
</Thumb.Template><br />
</Thumb><br />
<br />
<telerik:RadWindow Name="radWindow2" Header="" Width="272" MinHeight="100" MinWidth="100" Height="110" Canvas.Top="0" Canvas.Left="0" CanClose="False" Panel.ZIndex="1" ResizeMode="NoResize" Visibility="Collapsed" BorderThickness="1" IsHeaderHitTestVisible="True" ><br />
<telerik:RadWindow.HeaderTemplate><br />
<DataTemplate> <br />
<DockPanel Width="{Binding Width,ElementName=radWindow2}" VerticalAlignment="Top" HorizontalAlignment="Left"><br />
<StackPanel><br />
<TextBlock Text="RADWINDOW" FontSize="12" HorizontalAlignment="Left" Margin="0,5,0,2"></TextBlock><br />
</StackPanel><br />
<StackPanel Margin="0,0,14,0" ><br />
<telerik:RadButton Content="X" FontSize="9" Width="25" Height="18" FontWeight="Bold" Click="RadButton_Click" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="5,2,0,2"></telerik:RadButton><br />
</StackPanel><br />
</DockPanel><br />
</DataTemplate><br />
<br />
<br />
</telerik:RadWindow.HeaderTemplate><br />
<Grid > <br />
<StackPanel Orientation="Vertical"><br />
<TextBox Height="20" Width="80" Name="txtone"></TextBox><br />
<telerik:RadButton Content="Button" Height="Auto" HorizontalAlignment="Center" Name="radButton1" VerticalAlignment="Top" Width="Auto" Click="radButton1_Click" /><br />
</StackPanel><br />
<Thumb DragDelta="thumbh3_DragDelta" Width="{Binding Width,ElementName=radWindow2}" Height="15" VerticalAlignment="Bottom" Panel.ZIndex="2" Name="thumbh3" Visibility="{Binding Visibility,ElementName=radWindow2,Mode=TwoWay}" MouseEnter="thumbh3_MouseEnter" MouseLeave="thumbh3_MouseLeave"><br />
<Thumb.Template><br />
<ControlTemplate><br />
<TextBlock Text="" Background="Transparent"></TextBlock><br />
</ControlTemplate><br />
</Thumb.Template><br />
</Thumb><br />
<Thumb DragDelta="thumbh4_DragDelta" Height="{Binding Height,ElementName=radWindow2}" HorizontalAlignment="Right" Panel.ZIndex="2" Name="thumbh4" Visibility="{Binding Visibility,ElementName=radWindow2,Mode=TwoWay}" MouseEnter="thumbh4_MouseEnter" MouseLeave="thumbh4_MouseLeave" Width="10"><br />
<Thumb.Template><br />
<ControlTemplate><br />
<TextBlock Text="" Background="Transparent"></TextBlock><br />
</ControlTemplate><br />
</Thumb.Template><br />
</Thumb><br />
<Thumb DragDelta="thumbh5_DragDelta" HorizontalAlignment="Right" VerticalAlignment="Bottom" Panel.ZIndex="2" Name="thumbh5" Visibility="{Binding Visibility,ElementName=radWindow2,Mode=TwoWay}" MouseEnter="thumbh5_MouseEnter" MouseLeave="thumbh5_MouseLeave" Width="10"><br />
<Thumb.Template><br />
<ControlTemplate><br />
<TextBlock Text="" Background="Transparent"></TextBlock><br />
</ControlTemplate><br />
</Thumb.Template><br />
</Thumb> <br />
</Grid><br />
</telerik:RadWindow> <br />
</Canvas></div>
</span></b></div>
<script language="JavaScript" type="text/javascript">
<!--
function sizeTbl11(h) {
var tbl = document.getElementById('tbl3');
tbl.style.display = h;
}
// -->
</script><b>
<a href="javascript:sizeTbl11('none')">Hide</a>
<a href="javascript:sizeTbl11('block')">Expand</a>
<br />
<br />
</b><br />
<div class="MsoNormal">
<b><b><span lang="EN-US" style="font-family: "Verdana","sans-serif";">In
Coding View :
</span></b></b></div>
<div id="tbl2" name="tbl2" style="background-color: #ccccff; border: 0.02em solid Black; display: none; overflow: hidden; width: 600px;">
<b>private void Page_Loaded(object sender, RoutedEventArgs e)<br />
{<br />
thumbh3.DragDelta +=new System.Windows.Controls.Primitives.DragDeltaEventHandler(thumbh3_DragDelta);<br />
}<br />
<br />
public Icon icon { get; set; }<br />
<br />
private void button1_Click(object sender, RoutedEventArgs e)<br />
{<br />
if (radWindow2.Visibility == Visibility.Collapsed)<br />
{<br />
radWindow2.Visibility = Visibility.Visible;<br />
<br />
// SetCenter();<br />
}<br />
else<br />
{<br />
radWindow2.Visibility = Visibility.Collapsed; <br />
//SetCenter();<br />
}<br />
<br />
}<br />
private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)<br />
{<br />
movewindow(radWindow2, thumbh1, e);<br />
}<br />
<br />
public void movewindow(RadWindow radwindow, System.Windows.Controls.Primitives.Thumb thumb, System.Windows.Controls.Primitives.DragDeltaEventArgs e)<br />
{<br />
Canvas.SetLeft(radwindow, Canvas.GetLeft(thumb) + e.HorizontalChange);<br />
Canvas.SetTop(radwindow, Canvas.GetTop(thumb) + e.VerticalChange);<br />
Canvas.SetLeft(thumb, Canvas.GetLeft(thumb) + e.HorizontalChange);<br />
Canvas.SetTop(thumb, Canvas.GetTop(thumb) + e.VerticalChange); <br />
}<br />
<br />
<br />
<br />
private void thumbh3_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)<br />
{<br />
if (radWindow2.Height > radWindow2.MinHeight)<br />
{<br />
radWindow2.Height += e.VerticalChange; <br />
}<br />
else{<br />
radWindow2.Height = radWindow2.MinHeight + 4;<br />
thumbh3.ReleaseMouseCapture();<br />
}<br />
}<br />
<br />
private void thumbh3_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)<br />
{<br />
thumbh3.Cursor = System.Windows.Input.Cursors.SizeNS;<br />
}<br />
<br />
private void thumbh3_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)<br />
{<br />
thumbh3.Cursor = System.Windows.Input.Cursors.Arrow;<br />
}<br />
<br />
private void thumbh1_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)<br />
{<br />
thumbh1.Cursor = System.Windows.Input.Cursors.Hand;<br />
}<br />
<br />
private void thumbh1_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)<br />
{<br />
thumbh1.Cursor = System.Windows.Input.Cursors.Arrow;<br />
}<br />
<br />
private void thumbh4_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)<br />
{<br />
thumbh4.Cursor = System.Windows.Input.Cursors.SizeWE;<br />
}<br />
<br />
private void thumbh4_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)<br />
{<br />
thumbh4.Cursor = System.Windows.Input.Cursors.Arrow;<br />
}<br />
<br />
private void thumbh4_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)<br />
{<br />
if (radWindow2.Width > radWindow2.MinWidth)<br />
{<br />
radWindow2.Width += e.HorizontalChange;<br />
}<br />
else<br />
{<br />
radWindow2.Width = radWindow2.MinWidth + 4;<br />
thumbh4.ReleaseMouseCapture();<br />
}<br />
}<br />
<br />
private void thumbh5_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)<br />
{<br />
thumbh5.Cursor = System.Windows.Input.Cursors.Arrow;<br />
}<br />
<br />
private void thumbh5_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)<br />
{<br />
thumbh5.Cursor = System.Windows.Input.Cursors.SizeNWSE;<br />
}<br />
<br />
private void thumbh5_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)<br />
{<br />
if (radWindow2.Width > radWindow2.MinWidth)<br />
{<br />
if (e.HorizontalChange > 0)<br />
{<br />
radWindow2.Width += e.HorizontalChange;<br />
}<br />
else<br />
{<br />
radWindow2.Width = radWindow2.Width-4;<br />
}<br />
}<br />
else<br />
{<br />
radWindow2.Width = radWindow2.MinWidth + 4; <br />
}<br />
<br />
if (radWindow2.Height > radWindow2.MinHeight)<br />
{<br />
if (e.VerticalChange > 0)<br />
{<br />
radWindow2.Height += e.VerticalChange;<br />
}<br />
else<br />
{<br />
radWindow2.Height = radWindow2.Height-4;<br />
}<br />
}<br />
else<br />
{<br />
radWindow2.Height = radWindow2.MinHeight + 4; <br />
}<br />
}<br />
<br />
private void RadButton_Click(object sender, RoutedEventArgs e)<br />
{<br />
closewindow(radWindow2);<br />
}<br />
public void closewindow(RadWindow radwindow)<br />
{<br />
radwindow.Visibility = Visibility.Collapsed;<br />
}</b></div>
<script language="JavaScript" type="text/javascript">
<!--
function sizeTbl1(h) {
var tbl = document.getElementById('tbl2');
tbl.style.display = h;
}
// -->
</script><b>
<a href="javascript:sizeTbl1('none')">Hide</a>
<a href="javascript:sizeTbl1('block')">Expand</a>
<br />
<br />
</b><br />
<div class="separator" style="clear: both; float: left; text-align: center;">
<b><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheZMBWjWH6U7086x1cN8GjcnSeJbOWbfEo2VbWb02I5gg9Uum7r2MS0Iy6u7VfBR5SI2ER6L_A1FMETOZMshgwJ_Pj93oQORk8lr4tubTZONUG50woYQ-MMzE3JJYyM70jqb83cv0ycba0/s1600/ScreenHunter_19+Jun.+25+14.56.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="211" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheZMBWjWH6U7086x1cN8GjcnSeJbOWbfEo2VbWb02I5gg9Uum7r2MS0Iy6u7VfBR5SI2ER6L_A1FMETOZMshgwJ_Pj93oQORk8lr4tubTZONUG50woYQ-MMzE3JJYyM70jqb83cv0ycba0/s400/ScreenHunter_19+Jun.+25+14.56.jpg" width="400" /></a></b></div>
</div>
</div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com0tag:blogger.com,1999:blog-960565772270361327.post-64533870456994115332012-06-25T02:24:00.004-07:002012-06-26T08:53:38.288-07:00Display message in your pc Notification Area in WPF<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: "Verdana", "sans-serif";">Introduction :</span></b></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Verdana", "sans-serif";">How To Display message in your pc Notification Area in
WPF<br />
</span><br />
<span lang="EN-US" style="font-family: "Verdana", "sans-serif";"><br /></span></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: "Verdana", "sans-serif";">Descritption :</span></b></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Verdana", "sans-serif";">You can set Custom icon and Custom Message in Your Pc
Notification Area<br />
</span><br />
<span lang="EN-US" style="font-family: "Verdana", "sans-serif";"><br /></span></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: "Verdana", "sans-serif";">Using Code :</span></b><br />
<b><span lang="EN-US" style="font-family: "Verdana", "sans-serif";"><br /></span></b></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Verdana", "sans-serif";">This code for Notify Icon </span></div>
<div id="tbl11" name="tbl11" style="background-color: #ccccff; border: 0.02em solid Black; display: none; overflow: hidden; width: 600px;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">private</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> System.Windows.Forms.<span style="color: #2b91af;">NotifyIcon</span> notifyIcon1;</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">private</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> System.Windows.Forms.<span style="color: #2b91af;">ContextMenu</span> contextMenu1;</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">private</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> System.Windows.Forms.<span style="color: #2b91af;">MenuItem</span> menuItem1;</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">private</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> System.ComponentModel.<span style="color: #2b91af;">IContainer</span> components;</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">private</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">void</span>
button1_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">RoutedEventArgs</span> e)</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">{</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">this</span><span style="font-family: "Consolas"; font-size: 9.5pt;">.components = <span style="color: blue;">new</span> System.ComponentModel.<span style="color: #2b91af;">Container</span>();</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">this</span><span style="font-family: "Consolas"; font-size: 9.5pt;">.contextMenu1 = <span style="color: blue;">new</span> System.Windows.Forms.<span style="color: #2b91af;">ContextMenu</span>();</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">this</span><span style="font-family: "Consolas"; font-size: 9.5pt;">.menuItem1 = <span style="color: blue;">new</span> System.Windows.Forms.<span style="color: #2b91af;">MenuItem</span>();</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">// Initialize contextMenu1</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">this</span><span style="font-family: "Consolas"; font-size: 9.5pt;">.contextMenu1.MenuItems.AddRange(</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">new</span> System.Windows.Forms.<span style="color: #2b91af;">MenuItem</span>[]
{ <span style="color: blue;">this</span>.menuItem1 });</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">// Initialize menuItem1</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">this</span><span style="font-family: "Consolas"; font-size: 9.5pt;">.menuItem1.Index = 0;</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">this</span><span style="font-family: "Consolas"; font-size: 9.5pt;">.menuItem1.Text = <span style="color: #a31515;">"E&xit"</span>;</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">this</span><span style="font-family: "Consolas"; font-size: 9.5pt;">.menuItem1.Click += <span style="color: blue;">new</span> System.<span style="color: #2b91af;">EventHandler</span>(<span style="color: blue;">this</span>.menuItem1_Click);</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">//// Set up how the form should be displayed.</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">//this.ClientSize = new
System.Drawing.Size(292, 266);</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">//this.Text = "Notify Icon
Example";</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">// Create the NotifyIcon.</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">this</span><span style="font-family: "Consolas"; font-size: 9.5pt;">.notifyIcon1 = <span style="color: blue;">new</span> System.Windows.Forms.<span style="color: #2b91af;">NotifyIcon</span>(<span style="color: blue;">this</span>.components);</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">// The Icon property sets the icon that will
appear</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">// in the systray for this application.</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">//notifyIcon1.Icon = new Icon(@"F:\DMS
AMIT\dms2\DMSProject\DMSProject\bin\Debug\No.ico");</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">// Set an icon using code </span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">notifyIcon1 = <span style="color: blue;">new</span> <span style="color: #2b91af;">NotifyIcon</span>();</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: "Consolas"; font-size: 9.5pt;">Stream</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> iconStream = System.Windows.<span style="color: #2b91af;">Application</span>.GetResourceStream(<span style="color: blue;">new</span> <span style="color: #2b91af;">Uri</span>(<span style="color: #a31515;">"pack://application:,,,/Images/No.ico"</span>)).Stream;</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">notifyIcon1.Icon = <span style="color: blue;">new</span>
System.Drawing.<span style="color: #2b91af;">Icon</span>(iconStream); </span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">// The ContextMenu property sets the menu
that will</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">// appear when the systray icon is right
clicked.</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">notifyIcon1.ContextMenu = <span style="color: blue;">this</span>.contextMenu1;</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">// The Text property sets the text that will
be displayed,</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">// in a tooltip, when the mouse hovers over
the systray icon.</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">notifyIcon1.BalloonTipText = <span style="color: #a31515;">"dhaval"</span>;</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">notifyIcon1.BalloonTipTitle = <span style="color: #a31515;">"dhaval
error"</span>;</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">notifyIcon1.BalloonTipClicked += <span style="color: blue;">new</span>
<span style="color: #2b91af;">EventHandler</span>(<span style="color: blue;">this</span>.Balloon_DoubleClick);</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">notifyIcon1.Visible = <span style="color: blue;">true</span>;</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">notifyIcon1.ShowBalloonTip(5000);</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">notifyIcon1.Text = <span style="color: #a31515;">"Form1
(NotifyIcon example)"</span>;</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">// Handle the DoubleClick event to activate
the form.</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">notifyIcon1.Click += <span style="color: blue;">new</span>
System.<span style="color: #2b91af;">EventHandler</span>(<span style="color: blue;">this</span>.notifyIcon1_DoubleClick);</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">}</span></div>
<div class="MsoNormal">
<br /></div>
</div>
<script language="JavaScript" type="text/javascript">
<!--
function sizeTbl11(h) {
var tbl = document.getElementById('tbl11');
tbl.style.display = h;
}
// -->
</script>
<a href="javascript:sizeTbl11('none')">Hide</a>
<a href="javascript:sizeTbl11('block')">Expand</a>
<br />
<br />
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Verdana", "sans-serif";">This Code for Notify Icon Double </span></div>
<div id="tbl1" name="tbl1" style="background-color: #ccccff; border: 0.02em solid Black; display: none; overflow: hidden; width: 600px;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">private</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">void</span>
notifyIcon1_DoubleClick(<span style="color: blue;">object</span> Sender, <span style="color: #2b91af;">EventArgs</span> e)</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">{</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">//Write Down your code here when notify icon click</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">}</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
</div>
<script language="JavaScript" type="text/javascript">
<!--
function sizeTbl21(h) {
var tbl = document.getElementById('tbl1');
tbl.style.display = h;
}
// -->
</script>
<a href="javascript:sizeTbl21('none')">Hide</a>
<a href="javascript:sizeTbl21('block')">Expand</a>
<br />
<div class="MsoNormal">
<br />
<span lang="EN-US" style="font-family: "Verdana", "sans-serif";">This Code for </span><span style="font-family: "Consolas"; font-size: 9.5pt;">Balloon</span><span style="font-family: "Verdana", "sans-serif";"> <span lang="EN-US">Icon Double click</span></span></div>
<div id="tbl3" name="tbl3" style="background-color: #ccccff; border: 0.02em solid Black; display: none; overflow: hidden; width: 600px;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">private</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">void</span>
Balloon_DoubleClick(<span style="color: blue;">object</span> Sender, <span style="color: #2b91af;">EventArgs</span> e)</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">{</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Consolas"; font-size: 9.5pt;">//Write Down your code here where notify double click<br />
}</span></div>
</div>
<script language="JavaScript" type="text/javascript">
<!--
function sizeTbl31(h) {
var tbl = document.getElementById('tbl3');
tbl.style.display = h;
}
// -->
</script>
<a href="javascript:sizeTbl31('none')">Hide</a>
<a href="javascript:sizeTbl31('block')">Expand</a>
<br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiNmYPA3MHIDAm_7q8NjHuNs9oCzDyY7Qh0cDkL0OUmGr8cf5WLtbSVjl23VsrNANcg84ZRDHMGJZKkCKvMnOG5Wb9pI_MNShmKsdNHFE_E0dDuASr5kFD-qixVgnsM94O-7iIejwt4Z_a/s1600/ScreenHunter_19+Jun.+25+14.50.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="211" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiNmYPA3MHIDAm_7q8NjHuNs9oCzDyY7Qh0cDkL0OUmGr8cf5WLtbSVjl23VsrNANcg84ZRDHMGJZKkCKvMnOG5Wb9pI_MNShmKsdNHFE_E0dDuASr5kFD-qixVgnsM94O-7iIejwt4Z_a/s400/ScreenHunter_19+Jun.+25+14.50.jpg" width="400" /></a></div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com0tag:blogger.com,1999:blog-960565772270361327.post-77289683036284847842012-06-22T01:58:00.002-07:002012-06-26T08:54:34.076-07:00List Operation In C#<div dir="ltr" style="text-align: left;" trbidi="on">
This Blog Use For Major operation of List<> in C#<br />
Introduction<br />
Lists are considered generics and constructed types. You need to use < and > in the List declaration.<br />
List <> is Following Step<br />
1) Create Class for List
<br />
<div id="tbl1" name="tbl1" style="background-color: #ccccff; border: 0.02em solid Black; display: none; overflow: hidden; width: 600px;">
<div>
<table align="left" cellpadding="0" cellspacing="0" hspace="0" vspace="0">
<tbody>
<tr>
<td align="left" style="padding: 0cm 9pt;" valign="top"><div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">public</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">AddROSublet</span> </span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">string</span> _Id;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">string</span> _FaultId;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">string</span> _VendorName;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">string</span> _VendorId;<span style="color: blue;"> </span></span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> </span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span>
VendorName</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">get</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">return</span> _VendorName;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">set</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">
_VendorName = <span style="color: blue;">value</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span>
VendorId</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">get</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">return</span> _VendorId;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">set</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">
_VendorId = <span style="color: blue;">value</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> </span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> }</span></div>
</td>
</tr>
</tbody></table>
</div>
</div>
<script language="JavaScript" type="text/javascript">
<!--
function sizeTbl1(h) {
var tbl = document.getElementById('tbl1');
tbl.style.display = h;
}
// -->
</script>
<a href="javascript:sizeTbl1('none')">Hide</a>
<a href="javascript:sizeTbl1('block')">Expand</a>
<br />
<br />
<div class="MsoNormal">
2) Create object For List and Add Value in List</div>
<div class="MsoNormal">
</div>
<div id="tbl2" name="tbl2" style="background-color: #ccccff; border: 0.02em solid Black; display: none; overflow: hidden; width: 600px;">
<div>
<table align="left" cellpadding="0" cellspacing="0" hspace="0" vspace="0">
<tbody>
<tr>
<td align="left" style="padding: 0cm 9pt;" valign="top"><div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">public</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">Test</span>> lParts = <span style="color: blue;">new</span>
<span style="color: #2b91af;">List</span><<span style="color: #2b91af;">Test</span>>();</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;">lParts<span style="color: grey;">.</span><span style="color: blue;">Add</span><span style="color: grey;">(</span>new Test<span style="color: grey;">()</span></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt;">{</span><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: grey;"></span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> Id <span style="color: grey;">=</span> <span style="color: magenta;">1</span><span style="color: grey;">,</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> FId <span style="color: grey;">=</span> <span style="color: magenta;">“9999”</span><span style="color: grey;">,</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> Name <span style="color: grey;">=”Tejas”,</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> vId <span style="color: grey;">= 1003</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: grey;"></span></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt;">});</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;">lParts<span style="color: grey;">.</span><span style="color: blue;">Add</span><span style="color: grey;">(</span>new Test<span style="color: grey;">()</span></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt;">{</span><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: grey;"></span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> Id <span style="color: grey;">=</span> “2”<span style="color: grey;">,</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> FId <span style="color: grey;">=</span> <span style="color: magenta;">“9999”</span><span style="color: grey;">,</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> Name <span style="color: grey;">=”Dhaval”,</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> vId <span style="color: grey;">= 1002</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: grey;"></span></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt;">});</span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;">lParts<span style="color: grey;">.</span><span style="color: blue;">Add</span><span style="color: grey;">(</span>new Test<span style="color: grey;">()</span></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt;">{</span><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: grey;"></span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> Id <span style="color: grey;">=</span> <span style="color: magenta;">“3”</span><span style="color: grey;">,</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> FId <span style="color: grey;">=</span> <span style="color: magenta;">“9999”</span><span style="color: grey;">,</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> Name <span style="color: grey;">=”Amit”,</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> vId <span style="color: grey;">= 1001</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: grey;"></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<span style="color: grey; font-family: "Courier New"; font-size: 10pt;">});</span></div>
<a href="javascript:sizeTbl2('none')">Hide</a>
<a href="javascript:sizeTbl2('block')">Expand</a><br />
<br />
<div class="MsoNormal">
3)List Operation Related SpecificId one
column,ordr by,Gorup by</div>
<div id="tbl3" name="tbl3" style="background-color: #ccccff; border: 0.02em solid Black; display: none; overflow: hidden; width: 600px;">
<div>
<table align="left" cellpadding="0" cellspacing="0" hspace="0" vspace="0">
<tbody>
<tr>
<td align="left" style="padding: 0cm 9pt;" valign="top"><div class="MsoNormal">
<b><span style="color: grey; font-family: "Verdana", "sans-serif"; font-size: 10pt;">///</span></b><b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">This Code Give All Record for Spcific ID</span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">var</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> names1 = lParts.Where(n => n.</span><span style="font-family: "Courier New"; font-size: 10pt;"> vId </span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">== <span style="color: #a31515;">"1003"</span>).ToList();</span><b><span style="color: grey; font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: grey; font-family: "Verdana", "sans-serif"; font-size: 10pt;">///</span></b><b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">This Code Give only one value of Column</span></b><b><span style="font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">var</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> names1 = lParts.Where(n => n.</span><span style="font-family: "Courier New"; font-size: 10pt;"> vId </span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">== <span style="color: #a31515;">"1003"</span>)</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">.Select(n
=> n.VendorId).ToList();</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: grey; font-family: "Verdana", "sans-serif"; font-size: 10pt;">///</span></b><b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;"> This Code Give only one value of Column in one range
ex(1,0,0,3)</span></b><b><span style="font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">var</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> names2 = lParts.Where(n => n.</span><span style="font-family: "Courier New"; font-size: 10pt;"> vId </span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">== <span style="color: #a31515;">"1003"</span>)</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">.SelectMany(n
=> n.VendorId).ToList();</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: grey; font-family: "Verdana", "sans-serif"; font-size: 10pt;">///</span></b><b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">This Code For Group by and order
by</span></b><b><span style="font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">var</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> groupedList = lParts.GroupBy(c => <span style="color: blue;">new</span>
{ c.Name, c.VendorId })</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">.OrderBy(g
=> g.Key.Name).ThenBy(g => g.Key.VendorId).ToList();</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: grey; font-family: "Verdana", "sans-serif"; font-size: 10pt;">///</span></b><b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">This For Group by </span></b><b><span style="font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">var</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> groupedList1 = lParts.GroupBy(c => <span style="color: blue;">new</span>
{ c.Name, c.VendorId })</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">.ToList();</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//This Code for order by</span></b><b><span style="font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">var</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> groupedList2 = lParts.OrderBy(g => g.Name).ToList();</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//This code for Sum</span></b><b><span style="font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">var</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> sums = lParts.Sum(x => <span style="color: #2b91af;">Convert</span>.ToInt64(x.Id));</span></div>
</td>
</tr>
</tbody></table>
</div>
</div>
<script language="JavaScript" type="text/javascript">
<!--
function sizeTbl3(h) {
var tbl = document.getElementById('tbl3');
tbl.style.display = h;
}
// -->
</script>
<a href="javascript:sizeTbl3('none')">Hide</a>
<a href="javascript:sizeTbl3('block')">Expand</a>
<br />
<div class="MsoNormal">
4) List Operation Related Find Index </div>
<div id="tbl4" name="tbl4" style="background-color: #ccccff; border: 0.02em solid Black; display: none; overflow: hidden; width: 600px;">
<br />
<div>
<table align="left" cellpadding="0" cellspacing="0" hspace="0" vspace="0">
<tbody>
<tr>
<td align="left" style="padding: 0cm 9pt;" valign="top"><div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//Method 1 for find index</span></b><b><span style="font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">int</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> index = lParts.FindIndex(lparts => lparts.Id.Equals(<span style="color: #2b91af;">Convert</span>.ToString(“12345”),</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> <span style="color: #2b91af;">StringComparison</span>.Ordinal));</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//Method 2 for find index</span></b><b><span style="font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">int</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> index = lParts.FindIndex(</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">delegate</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">(<span style="color: #2b91af;">Test</span> sublet)</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">{</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> <span style="color: blue;">return</span>
sublet.Id == <span style="color: #2b91af;">Convert</span>.ToString(“12345”);</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">});</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">int</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> indexChild = lPartsChild.FindIndex(</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">delegate</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">(<span style="color: #2b91af;">Test</span> sublet)</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">{</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> <span style="color: blue;">return</span>
sublet.Id == <span style="color: #2b91af;">Convert</span>.ToString(“12345”);</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">});</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//Method 3 for find index</span></b><b><span style="font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">int</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> index = lParts.FindIndex(</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">delegate</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">(<span style="color: #2b91af;">Test</span> sublet)</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">{</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> <span style="color: blue;">return</span>
sublet.Id.Equals(“12345”, <span style="color: #2b91af;">StringComparison</span>.Ordinal);</span></div>
<div class="MsoNormal">
<span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">});</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//This Methos Find and then give last index</span></b><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">int</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> firstIndex = lTest.FindIndex(FindTest);</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//This Methos Find and then give last index</span></b><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">int</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> lastIndex = lTest.FindLastIndex(FindTest);</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//region Index of first in the second half of the collection</span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">int</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> mid = lTest.Count / 2;</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">int</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> halfIndex = lTest.FindIndex(mid, mid, FindTest);</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">#endregion</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//region Index of last in the second half of the collection</span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">int</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> halfLastIndex = lTest.FindLastIndex(lTest.Count - 1,
mid, FindTest);</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Consolas"; font-size: 9.5pt;">/</span></b><b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">/ Explicit predicate delegate.</span></b><b><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">private</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">bool</span> FindTest(Test tst)</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">{</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">if</span> (tst.MainId ==
Textbox1.Text)</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">return</span> <span style="color: blue;">true</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">else</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">return</span> <span style="color: blue;">false</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">}</span></div>
<div class="MsoNormal">
<br /></div>
</td>
</tr>
</tbody></table>
</div>
</div>
<a href="javascript:sizeTbl4('none')">Hide</a>
<a href="javascript:sizeTbl4('block')">Expand</a><br />
<script language="JavaScript" type="text/javascript">
<!--
function sizeTbl4(h) {
var tbl = document.getElementById('tbl4');
tbl.style.display = h;
}
// -->
</script>
<br />
<div class="MsoNormal">
5) List Operation Related to Find Operation</div>
<div id="tbl5" name="tbl5" style="background-color: #ccccff; border: 0.02em solid Black; display: none; overflow: hidden; width: 600px;">
<div>
<table align="left" cellpadding="0" cellspacing="0" hspace="0" vspace="0">
<tbody>
<tr>
<td align="left" style="padding: 0cm 9pt;" valign="top"><div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//Search and Update value by index value</span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">int</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> indexVA = -1;</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">indexVA = </span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">lParts</span><span style="font-family: "Consolas"; font-size: 9.5pt;">.FindIndex(</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">lparts</span><span style="font-family: "Consolas"; font-size: 9.5pt;">
=> Convert.ToString(</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">lparts</span><span style="font-family: "Consolas"; font-size: 9.5pt;">.FName).ToLower() == Convert.ToString(“tejas”);</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">if</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> (indexVA >= 0)</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">{</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: green;">//lTest[indexVA].Id = 1;</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: green;">//lTest[indexVA].FName = txtSearch.Text;</span></span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> </span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">lParts</span><span style="font-family: "Consolas"; font-size: 9.5pt;">
[indexVA].</span><span style="font-family: "Courier New"; font-size: 10pt;"> FId </span><span style="font-family: "Consolas"; font-size: 9.5pt;">=
100;</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">this</span>.viewMain.ItemsSource = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">this</span>.viewMain.ItemsSource = lTest;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">this</span>.viewMain.SelectedIndex = indexVA;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">}</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//Find First Record only</span></b></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">Test objTest = lTest.Find(</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">delegate</span><span style="font-family: "Consolas"; font-size: 9.5pt;">(Test objT)</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">{</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">return</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> objT.FId == Textbox1.Text;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">}</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">);</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: grey; font-family: "Verdana", "sans-serif"; font-size: 10pt;">///</span></b><b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">This For find only first record
from list</span></b><b><span style="font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">var</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> item = lParts.FirstOrDefault(x => x.</span><span style="font-family: "Courier New"; font-size: 10pt;"> vId </span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">== <span style="color: #a31515;">"1003"</span>);</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: grey; font-family: "Verdana", "sans-serif"; font-size: 10pt;">///T</span></b><b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">his for find only single record
from list</span></b><b><span style="font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Verdana", "sans-serif"; font-size: 9.5pt;">var</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> item1 = lParts.SingleOrDefault(x => x.FId == <span style="color: #a31515;">"9999"</span>);</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//Find Last Record only</span></b></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">Test objLastTest = lTest.FindLast(</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">delegate</span><span style="font-family: "Consolas"; font-size: 9.5pt;">(Test objT)</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">{</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">return</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> objT. FId ==
Textbox1.Text;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">}</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">);</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//Find All Record only</span></b><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">lTest = lTest.FindAll(</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">delegate</span><span style="font-family: "Consolas"; font-size: 9.5pt;">(Test objT)</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">{</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">return</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> objT. FId ==
Textbox1.Text;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">}</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">);</span><b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;"></span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">//This code for give range of array</span></b><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">Test[] output = lTest.GetRange(2, 3).ToArray();</span></div>
</td>
</tr>
</tbody></table>
</div>
</div>
<script language="JavaScript" type="text/javascript">
<!--
function sizeTbl5(h) {
var tbl = document.getElementById('tbl5');
tbl.style.display = h;
}
// -->
</script>
<a href="javascript:sizeTbl5('none')">Hide</a>
<a href="javascript:sizeTbl5('block')">Expand</a><br />
<br />
<div class="MsoListParagraph" style="text-indent: -18pt;">
6)List Operation Related Remove Operation</div>
<div id="tbl6" name="tbl6" style="background-color: #ccccff; border: 0.02em solid Black; display: none; overflow: hidden; width: 600px;">
<div>
<table align="left" cellpadding="0" cellspacing="0" hspace="0" vspace="0">
<tbody>
<tr>
<td align="left" style="padding: 0cm 9pt;" valign="top"><div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">#region Remove from list</span></b></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">lTest.Remove(lTest.Find(<span style="color: blue;">delegate</span>(Test
objT)</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">return</span> <span style="color: #2b91af;">Convert</span>.ToString(objT.Name).ToLower()
== “tejas”;</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> }));</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">#region Remove All from list</span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">if</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> (<span style="color: #2b91af;">Convert</span>.ToString(txtRemove.Text)
!= <span style="color: #a31515;">""</span>)</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">{</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">
lTest.RemoveAll(<span style="color: blue;">delegate</span>(Test objT)</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> <span style="color: blue;">return</span> <span style="color: #2b91af;">Convert</span>.ToString(objT.FName).ToLower()
== <span style="color: #2b91af;">Convert</span>.ToString(“tejas”).ToLower();</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;"> });</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">}</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">#region Remove from index</span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">int</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> indx = lTest.FindIndex(ltest => <span style="color: #2b91af;">Convert</span>.ToString(ltest.FName).ToLower() ==
“tejas”);</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">if</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> (indx >= 0)</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">
lTest.RemoveAt(indx);</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">#endregion</span><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">// Remove from range of class</span></b></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;">if</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> (indx >= 0)</span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">
lTest.RemoveRange(indx, 3);</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: green; font-family: "Verdana", "sans-serif"; font-size: 10pt;">// This Code For Reverse List</span></b><span style="font-family: "Consolas"; font-size: 9.5pt;"></span></div>
<div class="MsoNormal">
<span style="font-family: "Consolas"; font-size: 9.5pt;">lTest.Reverse();</span><span style="font-family: "Verdana", "sans-serif"; font-size: 9.5pt;"> </span></div>
</td>
</tr>
</tbody></table>
</div>
</div>
<script language="JavaScript" type="text/javascript">
<!--
function sizeTbl6(h) {
var tbl = document.getElementById('tbl6');
tbl.style.display = h;
}
// -->
</script>
<a href="javascript:sizeTbl6('none')">Hide</a>
<a href="javascript:sizeTbl6('block')">Expand</a><br />
This Very useful in WPF
</div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com1tag:blogger.com,1999:blog-960565772270361327.post-46880185756002377102012-06-06T01:42:00.001-07:002012-06-26T08:55:35.341-07:00Set Lost Focus and cusrosr go same control<div dir="ltr" style="text-align: left;" trbidi="on">
Method 1 <br />
setFocus(txts_StockNo);<br />
//set focus<br />
public static void setFocus(UIElement element)<br />
{<br />
if (!element.Focus())<br />
{<br />
element.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(delegate()<br />
{<br />
element.Focus();<br />
}));<br />
}<br />
else<br />
{<br />
element.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(delegate()<br />
{<br />
element.Focus();<br />
}));<br />
}<br />
}<br />
Method 2<br />
<br />
Write Down code on lost focus instead of PreviewLostKeyboardFocus_1<br />
<br />
private void txtPhone_PreviewLostKeyboardFocus_1(object sender, KeyboardFocusChangedEventArgs e)<br />
{<br />
if (txtPhone.Value.ToString().Length < 10 && txtPhone.Value.ToString().Length != 0)<br />
{<br />
MessageBox.Show("Enter 10 digit home number", "DMS", MessageBoxButton.OK, MessageBoxImage.Exclamation);<br />
//txtPhone.Focus();<br />
e.Handled = true;<br />
}<br />
else <br />
{<br />
if (Convert.ToString(txtPhone.Value) != "")<br />
{<br />
<br />
<br />
//// wrote down ur code<br />
<br />
<br />
}<br />
}</div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com0tag:blogger.com,1999:blog-960565772270361327.post-18266291269663452592012-06-01T10:31:00.001-07:002012-06-26T08:56:15.589-07:00Encrypt or Decrypt password using c# in ASP.Net<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="color: orange;">Introduction</span></b><br />
How to Convert Encrypt or Decrypt password using c# with asp.net
<br />
<br />
<div style="text-align: left;">
<b><span style="color: orange;">Using the code</span></b></div>
<div style="text-align: left;">
<br />
<b>Enter Your Password and first click on Encrypt button and then after click on Decrypt.</b></div>
1. Example Of First Enter Password = "tejasbhalani"<br />
2. EncodePasswordToBase64 function convert your string and give output<br />
ans= "cnJhYW5uYWFtbWVldHQ="<br />
3. DecodeFrom64 function convert your strring and give output<br />
ans="
tejasbhalani
"<br />
<table style="background-color: #d5d5ff;">
<tbody>
<tr>
<td><h2>
</h2>
<pre id="pre0" style="margin-top: 0pt;"><b><span class="code-comment">//</span><span class="code-comment">this function Convert to Encord your Password</span></b>
<span class="code-keyword">public</span> <span class="code-keyword">static</span> string EncodePasswordToBase64(string password)
{
<span class="code-keyword">try</span>
{
byte[] encData_byte = <span class="code-keyword">new</span> byte[password.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(password);
string encodedData = Convert.ToBase64String(encData_byte);
<span class="code-keyword">return</span> encodedData;
}
<span class="code-keyword">catch</span> (Exception ex)
{
<span class="code-keyword">throw</span> <span class="code-keyword">new</span> Exception(<span class="code-string">"</span><span class="code-string">Error in base64Encode"</span> + ex.Message);
}
}</pre>
</td>
</tr>
</tbody>
</table>
<br />
<table height="186" style="background-color: #d5d5ff;">
<tbody>
<tr>
<td><pre style="margin-top: 0pt;"><span class="code-comment">//</span><span class="code-comment">this function Convert to Decord your Password</span><span class="code-keyword">
public</span> string DecodeFrom64(string encodedData)
{
System.Text.UTF8Encoding encoder = <span class="code-keyword">new</span> System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(encodedData);
<span class="code-keyword">int</span> charCount = utf8Decode.GetCharCount
(todecode_byte, <span class="code-digit">0</span>, todecode_byte.Length);
<span class="code-keyword">char</span>[] decoded_char = <span class="code-keyword">new</span> <span class="code-keyword">char</span>[charCount];
utf8Decode.GetChars(todecode_byte, <span class="code-digit">0</span>, todecode_byte.Length, decoded_char, <span class="code-digit">0</span>);
string result = <span class="code-keyword">new</span> <span class="code-SDKkeyword">String</span>(decoded_char);
<span class="code-keyword">return</span> result;
}</pre>
<br />
<br />
<br />
<pre id="pre3" style="margin-top: 0pt;"><span class="code-keyword">protected</span> <span class="code-keyword">void</span> Button1_Click(<span class="code-keyword">object</span> sender, EventArgs e)
{
Label1.Text=EncodePasswordToBase64(TextBox1.Text);
}
<pre id="pre4" style="margin-top: 0pt;"><span class="code-keyword">protected</span> <span class="code-keyword">void</span> Button2_Click(<span class="code-keyword">object</span> sender, EventArgs e)
{
Label1.Text = DecodeFrom64(Label1.Text);
}</pre>
</pre>
<br /></td>
</tr>
</tbody></table>
<br />
This Code Successfully Run in C#</div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com0tag:blogger.com,1999:blog-960565772270361327.post-88504030953528585982012-06-01T10:11:00.000-07:002012-06-26T08:56:36.402-07:00Send Mail With Attachment File Using C# in ASP.NET<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="color: orange;">Introduction</span></b><br />
This article lists code to send a mail with an attachment file.<br />
<br />
<div style="text-align: left;">
<b><span style="color: orange;">Background</span></b></div>
We send mail using <code>System.Net.Mail</code>.<br />
<br />
<div style="text-align: left;">
<b><span style="color: orange;">Using the code</span></b>
<br />
<table style="background-color: #d5d5ff;">
<tbody>
<tr>
<td>string ToAddress = TextBox3.Text;
const string FromAddress = YourGmailId; //ForExample:tejasbhalani@gmail.com
</td></tr>
</tbody></table>
</div>
<br />
<table style="background-color: #d5d5ff;">
<tbody>
<tr>
<td><pre id="pre1" lang="cs" style="margin-top: 0pt;"><span class="code-keyword">string</span> Subject = TextBox6.Text;
<span class="code-SDKkeyword">String</span> Body = TextBox4.Text;
System.Net.Mail.MailMessage mail = <span class="code-keyword">new</span> System.Net.Mail.MailMessage();
mail.To.Add(ToAddress);
mail.From = <span class="code-keyword">new</span> MailAddress(FromAddress);
mail.Subject = Subject;
mail.Body = Body;
<span class="code-keyword">if</span> (FileUpload1.PostedFile != <span class="code-keyword">null</span>)
{
HttpPostedFile attFile = FileUpload1.PostedFile;
<span class="code-keyword">int</span> attachFileLength = attFile.ContentLength;
<span class="code-keyword">if</span> (attachFileLength > <span class="code-digit">0</span>)
{
FileNameToAttache = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath(FileNameToAttache));
mail.Attachments.Add(<span class="code-keyword">new</span> Attachment(Server.MapPath(FileNameToAttache)));
}
}
mail.Priority = System.Net.Mail.MailPriority.High;
SmtpClient client = <span class="code-keyword">new</span> SmtpClient();
client.Credentials = <span class="code-keyword">new</span> System.Net.NetworkCredential(FromAddress, <span class="code-string">"</span><span class="code-string">YourGmailPassword"</span>);
client.Port = <span class="code-digit">587</span>; <span class="code-comment">//</span><span class="code-comment"> Gmail works on this port</span>client.Host = <span class="code-string">"</span><span class="code-string">smtp.gmail.com"</span>;
client.EnableSsl = <span class="code-keyword">true</span>; <span class="code-comment">//</span><span class="code-comment">Gmail works on Server Secured Layer</span><span class="code-keyword">try</span>
{
client.Send(mail);
}
<span class="code-keyword">catch</span> (Exception error)
{
<span class="code-keyword">throw</span> error;
}</pre>
</td>
</tr>
</tbody>
</table>
<br />
This Code For Succesfully Run............
</div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com0tag:blogger.com,1999:blog-960565772270361327.post-89734109010157199702012-06-01T09:54:00.001-07:002012-06-26T08:57:04.341-07:00CheckBoxList in Wpf With C#<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: orange;"><b>Introduction</b></span><br />
<br />
Display Selected Column Dynamically Using checkBoxList in Wpf With C# Demo<br />
<br />
<b><span style="color: orange;">Using the code</span></b><br />
You Want to Display Selected Column Dynamically run time Using CheckBoxList then Just Use this Code in your application.<br />
<br />
First Create one Data base<br />
Example of -><br />
<br />
-- DataBase Name :- db<br />
-- Create Five Column<br />
-- Id Name Address City Phone<br />
-- Enter some data in database<br />
<br />
<div style="text-align: left;">
<b><span style="color: orange;">First We Create Form Design</span></b><b><span style="color: orange;"><br /></span></b>
</div>
<div style="text-align: left;">
<table style="background-color: #d5d5ff;">
<tbody>
<tr>
<td><pre id="pre0" lang="C++" style="margin-top: 0pt;"><Grid>
<Grid Margin=<span class="code-string">"</span><span class="code-string">20,12,0,180"</span> HorizontalAlignment=<span class="code-string">"</span><span class="code-string">Left"</span> Width=<span class="code-string">"</span><span class="code-string">256"</span> VerticalAlignment=<span class="code-string">"</span><span class="code-string">Top"</span>>
<GroupBox Header=<span class="code-string">"</span><span class="code-string">Select Column"</span> Margin=<span class="code-string">"</span><span class="code-string">0,0,6,-113"</span>>
<telerik:RadWrapPanel Name=<span class="code-string">"</span><span class="code-string">RadWrapPanel1"</span> VerticalAlignment=<span class="code-string">"</span><span class="code-string">Top"</span> Height=<span class="code-string">"</span><span class="code-string">auto"</span> HorizontalAlignment=<span class="code-string">"</span><span class="code-string">Left"</span> Width=<span class="code-string">"</span><span class="code-string">auto"</span>></telerik:RadWrapPanel>
</GroupBox>
</Grid>
<telerik:RadGridView HorizontalAlignment=<span class="code-string">"</span><span class="code-string">Left"</span> Margin=<span class="code-string">"</span><span class="code-string">0,131,0,0"</span> Name=<span class="code-string">"</span><span class="code-string">radGridView1"</span> ShowGroupPanel=<span class="code-string">"</span><span class="code-string">False"</span> VerticalAlignment=<span class="code-string">"</span><span class="code-string">Top"</span> Width=<span class="code-string">"</span><span class="code-string">288"</span> />
</Grid>
</pre>
</td>
</tr>
</tbody>
</table>
</div>
<div style="text-align: left;">
<span style="color: orange;"><b><br /></b></span></div>
<div style="text-align: left;">
<span style="color: orange;"><b>This Code Write down in your code file</b></span></div>
<div style="text-align: left;">
<br /></div>
<table style="background-color: #d5d5ff;">
<tbody>
<tr>
<td>public partial class onlytestingform : Page<br />
{<br />
//Declare Connection String and other object<br />
SqlConnection con = new SqlConnection(@"Enter your Connection String");<br />
SqlCommand cmd = new SqlCommand();<br />
SqlDataAdapter da = new SqlDataAdapter();<br />
DataSet ds = new DataSet();<br />
DataTable dt = new DataTable();<br />
public List<System.Windows.Controls.CheckBox> checkBoxList = new List<System.Windows.Controls.CheckBox>();<br />
public System.Windows.Controls.CheckBox chk;<br />
public onlytestingform()<br />
{<br />
InitializeComponent();<br />
}<br />
private void Page_Loaded(object sender, RoutedEventArgs e)<br />
{<br />
//Call your Function For Fill Your Grid Load Time<br />
fillgrid();<br />
//Call your Function For Fill Your RadWrapPanel1 Load Time<br />
BindParts();<br />
}<br />
//Fill Your Grid First<br />
public void fillgrid()<br />
{<br />
con.Open();<br />
string sql="select * from db";<br />
cmd = new SqlCommand(sql,con);<br />
da.SelectCommand = cmd;<br />
da.Fill(ds);<br />
<br />
if (ds.Tables[0].Rows.Count > 0)<br />
{<br />
radGridView1.ItemsSource = ds.Tables[0].DefaultView;<br />
}<br />
con.Close();<br />
}<br />
<br />
//Bind Column in RadWrapPanel1 With CheckBox Using GridView Column<br />
public void BindParts()<br />
{<br />
checkBoxList.Clear();<br />
for (int i = 0; i < radGridView1.Columns.Count; i++)<br />
{<br />
chk = new System.Windows.Controls.CheckBox();<br />
checkBoxList.Add(chk);<br />
RadWrapPanel1.Children.Add(chk);<br />
chk.Width = 150;<br />
chk.Height = 22;<br />
chk.Content = Convert.ToString(radGridView1.Columns[i].Header);<br />
chk.IsChecked = true;<br />
chk.Checked += new RoutedEventHandler(chk_Checked);<br />
chk.Unchecked += new RoutedEventHandler(chk_Unchecked);<br />
}<br />
}<br />
//Hide Column Code<br />
void chk_Unchecked(object sender, RoutedEventArgs e)<br />
{<br />
List<string> chkUnchekList = new List<string>();<br />
chkUnchekList.Clear();<br />
foreach (System.Windows.Controls.CheckBox item in checkBoxList)<br />
{<br />
if (item.IsChecked == false)<br />
{<br />
chkUnchekList.Add(item.Content.ToString());<br />
}<br />
}<br />
for (int i = 0; i < radGridView1.Columns.Count; i++)<br />
{<br />
if (chkUnchekList.Contains(radGridView1.Columns[i].Header.ToString()))<br />
{<br />
radGridView1.Columns[i].IsVisible = false;<br />
}<br />
}<br />
}<br />
<br />
//Un-Hide Column Code<br />
void chk_Checked(object sender, RoutedEventArgs e)<br />
{<br />
List<string> chkCheckList = new List<string>();<br />
chkCheckList.Clear();<br />
foreach (System.Windows.Controls.CheckBox item in checkBoxList)<br />
{<br />
if (item.IsChecked == true)<br />
{<br />
chkCheckList.Add(item.Content.ToString());<br />
}<br />
}<br />
for (int i = 0; i < radGridView1.Columns.Count; i++)<br />
{<br />
if (chkCheckList.Contains(radGridView1.Columns[i].Header.ToString()))<br />
{<br />
radGridView1.Columns[i].IsVisible = true;<br />
}<br />
}<br />
}<br />
}
</td>
</tr>
</tbody>
</table>
<br />
This Code Succefully Run.............</div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com0tag:blogger.com,1999:blog-960565772270361327.post-41070517758242148092012-05-28T10:07:00.004-07:002012-06-26T08:57:32.898-07:00Insert, Delete and Update in generic list in C#<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="color: orange;">Introduction</span></b><br />
This Code for Insert Update and Delete in Generic List in ASP.Net with C#<br />
<br />
<b><span style="color: orange;">Using This Code</span></b><br />
Insert Update and Delete in List<br />
<br />
<table style="background-color: #d5d5ff;">
<tbody>
<tr>
<td><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">using</span><span style="font-family: "consolas"; font-size: 9.5pt;"> System;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">using</span><span style="font-family: "consolas"; font-size: 9.5pt;"> System.Collections.Generic;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">using</span><span style="font-family: "consolas"; font-size: 9.5pt;"> System.ComponentModel;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">using</span><span style="font-family: "consolas"; font-size: 9.5pt;"> System.Data;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">using</span><span style="font-family: "consolas"; font-size: 9.5pt;"> System.Drawing;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">using</span><span style="font-family: "consolas"; font-size: 9.5pt;"> System.Text;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">using</span><span style="font-family: "consolas"; font-size: 9.5pt;"> System.Windows.Forms;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">namespace</span><span style="font-family: "consolas"; font-size: 9.5pt;"> GenericList</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">{</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">frmContact</span> : Form</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> List contacts;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">public</span> frmContact()</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> InitializeComponent();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<h2>
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"> <b> # region</b></span><b><span style="font-family: "consolas"; font-size: 9.5pt;"> Insert Operation</span></b></h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">private</span> <span style="color: blue;">void</span> btnInsert_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: #2b91af;">Customer</span> cnt = <span style="color: blue;">new</span> <span style="color: #2b91af;">Customer</span>();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> cnt.Name = txtName.Text.Trim();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> cnt.Mobile = txtMobile.Text.Trim();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> contacts.Add(cnt);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> CurrencyManager cm = (CurrencyManager)<span style="color: blue;">this</span>.BindingContext[contacts];</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> cm.Refresh();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> dgcontacts.DataSource = contacts;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"> # endregion</span> <br />
<h2>
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"> #region</span><span style="font-family: "consolas"; font-size: 9.5pt;"> Update Operation</span></h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">private</span> <span style="color: blue;">void</span> btnUpdate_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> List select = contacts.FindAll(<span style="color: blue;">new</span> Predicate(HasName));</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">if</span> (select.Count > 0) <span style="color: green;">// record found</span></span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">foreach</span> (<span style="color: #2b91af;">Customer</span> cnt <span style="color: blue;">in</span> select)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> cnt.Name = txtName.Text.Trim();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> cnt.Mobile = txtMobile.Text.Trim();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> CurrencyManager cm = (CurrencyManager)<span style="color: blue;">this</span>.BindingContext[contacts];</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> cm.Refresh();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> dgcontacts.DataSource = contacts;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"> else</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> MessageBox.Show(<span style="color: #a31515;">"No records found"</span>);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"> # endregion</span> <br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;"> //This function will check for the person name</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">bool</span> HasName(<span style="color: #2b91af;">Customer</span> c)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">return</span> (c.Name == txtName.Text);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<h2>
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"> # region</span><span style="font-family: "consolas"; font-size: 9.5pt;"> Delete Operation</span></h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">private</span> <span style="color: blue;">void</span> btnDelete_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> List select = contacts.FindAll(<span style="color: blue;">new</span> Predicate(HasName));</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">if</span> (select.Count > 0) <span style="color: green;">// record found</span></span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">foreach</span> (<span style="color: #2b91af;">Customer</span> cnt <span style="color: blue;">in</span> select)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> contacts.Remove(cnt);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> CurrencyManager cm = (CurrencyManager)<span style="color: blue;">this</span>.BindingContext[contacts];</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> cm.Refresh();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> dgcontacts.DataSource = contacts;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"> else</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> MessageBox.Show(<span style="color: #a31515;">"No records found"</span>);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"> # endregion</span> <br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">private</span> <span style="color: blue;">void</span> frmContact_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> contacts = <span style="color: blue;">new</span> List();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<h2>
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;"> //Customer Class</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Customer</span></span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">private</span> <span style="color: blue;">string</span> _Name;</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">private</span> <span style="color: blue;">string</span> _Mobile;</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> Name</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">get</span> { <span style="color: blue;">return</span> _Name; }</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">set</span> { _Name = <span style="color: blue;">value</span>; }</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> Mobile</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> {</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">get</span> { <span style="color: blue;">return</span> _Mobile; }</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">set</span> { _Mobile = <span style="color: blue;">value</span>; }</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span></h2>
<h2>
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span></h2>
<span style="font-family: "consolas"; font-size: 9.5pt;">}</span></td>
</tr>
</tbody>
</table>
</div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com1tag:blogger.com,1999:blog-960565772270361327.post-23166397938739889712012-05-28T09:50:00.000-07:002012-06-26T08:58:01.759-07:00C# Code To make thumbnails of full size images<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: orange;"><b>Intriduction</b></span><span style="color: orange;"><b><br /></b></span><br />
This Code use for to mkae thumbnailspf full size images..
<span style="color: orange;"><b><br /></b></span><br />
<br />
<span style="color: orange;"><b>This is to written in fileupload code behind</b></span><span style="color: orange;"><b><br /></b></span><br />
<table style="background-color: #d5d5ff;">
<tbody>
<tr>
<td><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">if</span><span style="font-family: "consolas"; font-size: 9.5pt;"> (FileUpload4.FileName != <span style="color: #a31515;">""</span>)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">{</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">string</span><span style="font-family: "consolas"; font-size: 9.5pt;"> appPath = Request.PhysicalApplicationPath;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">path = appPath + <span style="color: #a31515;">"Images\\"</span> + FileUpload4.FileName;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">path6 = <span style="color: #a31515;">"Images/Thumbnail/"</span> + FileUpload4.FileName;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">FileUpload4.SaveAs(Server.MapPath(<span style="color: #a31515;">"../Images/"</span> + FileUpload4.FileName));</span><br />
<br />
<span style="font-family: "consolas"; font-size: 9.5pt;">System.Drawing.<span style="color: #2b91af;">Image</span> ImageToSave = resizeImage(System.Drawing.<span style="color: #2b91af;">Image</span>.FromStream(FileUpload4.FileContent), <span style="color: blue;">new</span> <span style="color: #2b91af;">Size</span>(150, 150));</span><br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">// supply actual image to the function</span> <br />
<span style="font-family: "consolas"; font-size: 9.5pt;">ImageToSave.Save(Server.MapPath(System.IO.<span style="color: #2b91af;">Path</span>.Combine(<span style="color: #a31515;">"../Images/Thumbnail/"</span>, FileUpload4.FileName)));</span><br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">// the function returns a thumbnail which is saved here</span> <br />
<br />
<span style="font-family: "consolas"; font-size: 9.5pt;">}</span></td>
</tr>
</tbody>
</table>
<span style="color: orange;"><b><br /></b></span><br />
<span style="color: orange;"><b>This is drawing function that is place below above code</b></span><span style="color: orange;"><b><br /></b></span><br />
<table style="background-color: #d5d5ff;">
<tbody>
<tr><td><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">private</span><span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">static</span> System.Drawing.<span style="color: #2b91af;">Image</span> resizeImage(System.Drawing.<span style="color: #2b91af;">Image</span> imgToResize, <span style="color: #2b91af;">Size</span> size)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">{</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">int</span><span style="font-family: "consolas"; font-size: 9.5pt;"> sourceWidth = imgToResize.Width;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">int</span><span style="font-family: "consolas"; font-size: 9.5pt;"> sourceHeight = imgToResize.Height;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">float</span><span style="font-family: "consolas"; font-size: 9.5pt;"> nPercent = 0;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">float</span><span style="font-family: "consolas"; font-size: 9.5pt;"> nPercentW = 0;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">float</span><span style="font-family: "consolas"; font-size: 9.5pt;"> nPercentH = 0;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">nPercentW = ((<span style="color: blue;">float</span>)size.Width / (<span style="color: blue;">float</span>)sourceWidth);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">nPercentH = ((<span style="color: blue;">float</span>)size.Height / (<span style="color: blue;">float</span>)sourceHeight);</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">if</span><span style="font-family: "consolas"; font-size: 9.5pt;"> (nPercentH < nPercentW)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">nPercent = nPercentH;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">else</span> <br />
<span style="font-family: "consolas"; font-size: 9.5pt;">nPercent = nPercentW;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">int</span><span style="font-family: "consolas"; font-size: 9.5pt;"> destWidth = (<span style="color: blue;">int</span>)(sourceWidth * nPercent);</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">int</span><span style="font-family: "consolas"; font-size: 9.5pt;"> destHeight = (<span style="color: blue;">int</span>)(sourceHeight * nPercent);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">Bitmap b = <span style="color: blue;">new</span> Bitmap(destWidth, destHeight);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">Graphics g = Graphics.FromImage((System.Drawing.<span style="color: #2b91af;">Image</span>)b);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">g.InterpolationMode = InterpolationMode.HighQualityBicubic;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">g.Dispose();</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">return</span><span style="font-family: "consolas"; font-size: 9.5pt;"> (System.Drawing.<span style="color: #2b91af;">Image</span>)b;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">} </span></td></tr>
</tbody>
</table>
<span style="color: orange;"><b>namespace to be included</b></span>
<br />
<span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;"><span style="color: blue;">using</span> System.IO;<br />using</span><span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;"> System.Drawing;<br />using</span><span style="color: blue; font-family: "Consolas"; font-size: 9.5pt;"> System.Drawing.Imaging;<br />using</span><span style="font-family: "Consolas"; font-size: 9.5pt;"> System.Drawing.Drawing2D; </span></div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com0tag:blogger.com,1999:blog-960565772270361327.post-781892109000149262012-05-28T08:04:00.000-07:002012-06-26T08:58:22.564-07:00Online Payments Using Paypal with Asp.Net with C#<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: orange;"><b>Introduction</b></span><br />
<br />
this code for Online Payments Using Paypal with Asp.Net <br />
<b><span style="color: orange;">Description </span></b><br />
<br />
I am going to explain Step by Step Procedure, about integrating PayPal account with asp. <br />
<br />
<b><span style="color: orange;">Step-1</span></b> Create a First Paypal Merchant Account.<br />
--this Account Create for Salling purpose.<br />
<br />
<b><span style="color: orange;">Step-2</span></b> Create a Second Paypal Buyer Account.<br />
--this Account Create for purchasing purpose. <br />
<br />
<b><span style="color: orange;">Using the code</span></b><br />
I am going to explain Step by Step Procedure, about integrating PayPal account with asp.net Code.<br />
<br />
you want to do online transaction using paypal. Use this Example in your project.. <br />
<br />
This Code is Declare on your Button Click Event. <br />
<br />
<table style="background-color: #d5d5ff;">
<tbody>
<tr><td><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">const</span><span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">string</span> Server_URL = <span style="color: #a31515;">"https://www.sandbox.paypal.com/cgi-bin/webscr?"</span>;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">const</span><span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">string</span> return_URL = <span style="color: #a31515;">"https://www.paypal.com/xclick/Sample@gmail.com"</span>;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">const</span><span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">string</span> cancelreturn_URL = <span style="color: #a31515;">"http://www.PageWhenCancel.com/cc.fail.aspx"</span>;</span><br />
<br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//Assigning Cmd Path as Statically to Parameter</span> <br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">string</span><span style="font-family: "consolas"; font-size: 9.5pt;"> cmd = <span style="color: #a31515;">"_xclick"</span>;</span><br />
<br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//Assigning business Id as Statically to Parameter</span> <br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">string</span><span style="font-family: "consolas"; font-size: 9.5pt;"> business = <span style="color: #a31515;">"tejasn_1338137871_biz@gmail.com"</span>;<span style="color: green;">// Enter your business account here</span></span><br />
<br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//Assigning item name as Statically to Parameter</span> <br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">string</span><span style="font-family: "consolas"; font-size: 9.5pt;"> item_name = <span style="color: #a31515;">"balagi waffers"</span>;</span><br />
<br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//Passing Amount as Statically to parameter</span> <br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">int</span><span style="font-family: "consolas"; font-size: 9.5pt;"> amount = 1000;</span><br />
<br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//Passing Currency as Statically to parameter</span> <br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">string</span><span style="font-family: "consolas"; font-size: 9.5pt;"> currency_code = <span style="color: #a31515;">"USD"</span>;</span><br />
<br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">string</span><span style="font-family: "consolas"; font-size: 9.5pt;"> redirect = <span style="color: #a31515;">""</span>;</span><br />
<br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//Pass your Server_Url,cmd,business,item_name,amount,currency_code variable</span> <br />
<span style="font-family: "consolas"; font-size: 9.5pt;">redirect += Server_URL;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">redirect += <span style="color: #a31515;">"cmd="</span> + cmd;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">redirect += <span style="color: #a31515;">"&business="</span> + business;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">redirect += <span style="color: #a31515;">"&item_name="</span> + item_name;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">redirect += <span style="color: #a31515;">"&amount="</span> + amount;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">redirect += <span style="color: #a31515;">"&currency_code="</span> + currency_code;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">redirect += <span style="color: #a31515;">"&return="</span> + return_URL;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">redirect += <span style="color: #a31515;">"&cancel_return"</span> + cancelreturn_URL;</span><br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//Redirect to the payment page</span> <br />
<span style="font-family: "consolas"; font-size: 9.5pt;">Response.Redirect(redirect);</span></td></tr>
</tbody>
</table>
<b><span style="color: orange;"><br /></span></b><br />
<b><span style="color: orange;">After Click on Send Button just follow this step </span></b><br />
--when you purchase any one value using your seller id.. <br />
--Enter your id and password run time on paypal payment time.. <br />
Example of :- tejasbhalani_per@gmail.com
<br />
This Code Sucessfully Run</div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com4tag:blogger.com,1999:blog-960565772270361327.post-2044586853367629612012-05-27T08:25:00.000-07:002012-06-26T08:58:43.761-07:00Open PDF file in new browser tab using ASP.NET with C#<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<b><span style="color: orange;">Introduction</span></b></div>
<div style="text-align: left;">
This tip describes how to open a PDF file in a new browser tab using ASP.NET with C#. </div>
<div style="text-align: left;">
<span style="color: orange;"><b><br /></b></span></div>
<div style="text-align: left;">
<span style="color: orange;"><b>Using the code</b></span><b><br /></b></div>
<div style="text-align: left;">
We create a folder in our project and store the PDF in this folder. </div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<span style="color: orange;"><b>
//Java Script for that</b></span></div>
<div style="text-align: left;">
<table style="background-color: #d5d5ff;">
<tbody>
<tr><td><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: red;">type</span><span style="color: blue;">="text/javascript"></span></span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">function</span> openPDF() {</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">var</span> strMessage = <span style="color: maroon;">'<span style="background: none repeat scroll 0% 0% yellow;"><%</span>= p<span style="background: none repeat scroll 0% 0% yellow;">%></span>'</span>;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">var</span> a = <span style="color: maroon;">'http://localhost:2878/your project name/'</span> + strMessage;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> window.open(a, <span style="color: maroon;">'PDF'</span>);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">return</span> <span style="color: blue;">true</span>;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;"> }</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"></</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span> </td></tr>
</tbody>
</table>
<div style="text-align: left;">
<br />
<table style="background-color: #d5d5ff;">
<tbody>
<tr>
<td><span style="color: green; font-family: "consolas"; font-size: 9.5pt;">// Create one public variable p.</span> <br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">public</span><span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">string</span> p;</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">protected</span><span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">void</span> GridView1_RowCommand(<span style="color: blue;">object</span> sender, GridViewCommandEventArgs e)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">{</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">p = e.CommandArgument.ToString();</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">this</span><span style="font-family: "consolas"; font-size: 9.5pt;">.Page.ClientScript.RegisterStartupScript(<span style="color: blue;">this</span>.GetType(),</span><br />
<span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"page_index_script"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<span style="color: #a31515;">"openPDF();"</span>,<span style="color: blue;">true</span>);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">}</span><br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//p variable is provide path..</span> <br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//For Example:-"E-book/tejasvbhalani.pdf"</span> <br />
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//E-book is our folder name and tejasvbhalani is our pdf file name.. </span></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com11tag:blogger.com,1999:blog-960565772270361327.post-3483740311165389932012-05-27T06:53:00.000-07:002012-06-26T08:59:14.508-07:00Sending Email using C# and ASP.Net<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<span style="color: orange;"><b>Introduction</b></span></div>
This tip describes how to send email using ASP.NET with C# and using a GMail or Yahoo! port.<br />
<br />
<span style="color: orange;"><b>Background</b></span><span style="color: orange;"><b><br /></b></span><br />
This code uses the System.Net.Mail namespace.<br />
<br />
<span style="color: orange;"><b>Using the code</b></span><br />
<b><span style="color: orange;">//Sending Mail Using Gmail</span></b><b><span style="color: orange;"><br /></span></b><br />
<table style="background-color: #d5d5ff;">
<tbody>
<tr>
<td><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">const</span><span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">string</span> FromAddress = <span style="color: #a31515;">"your gmail id"</span>;<span style="color: green;">//For Example tejasbhalani@gmail.com</span></span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">string</span><span style="font-family: "consolas"; font-size: 9.5pt;"> Subject = TextBox6.Text;</span><br />
<span style="color: #2b91af; font-family: "consolas"; font-size: 9.5pt;">String</span><span style="font-family: "consolas"; font-size: 9.5pt;"> Body = TextBox4.Text;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">System.Net.Mail.<span style="color: #2b91af;">MailMessage</span> mail = <span style="color: blue;">new</span> System.Net.Mail.<span style="color: #2b91af;">MailMessage</span>();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">mail.To.Add(ToAddress);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">mail.From = <span style="color: blue;">new</span> MailAddress(FromAddress)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">mail.Subject = Subject;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">mail.Body = Body;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">mail.Priority = System.Net.Mail.<span style="color: #2b91af;">MailPriority</span>.High;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">SmtpClient client = <span style="color: blue;">new</span> SmtpClient();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">client.Credentials = <span style="color: blue;">new</span> System.Net.<span style="color: #2b91af;">NetworkCredential</span>(FromAddress, <span style="color: #a31515;">"gmail id password"</span>);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">client.Port = 587; <span style="color: green;">// Gmail works on this port</span></span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">client.Host = <span style="color: #a31515;">"smtp.gmail.com"</span>;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">client.EnableSsl = <span style="color: blue;">true</span>; <span style="color: green;">//Gmail works on Server Secured Layer</span></span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">try</span> <br />
<span style="font-family: "consolas"; font-size: 9.5pt;">{</span><br />
<div style="text-indent: 36pt;">
<span style="font-family: "consolas"; font-size: 9.5pt;">client.Send(mail);</span></div>
<span style="font-family: "consolas"; font-size: 9.5pt;">}</span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">catch</span><span style="font-family: "consolas"; font-size: 9.5pt;"> (<span style="color: #2b91af;">Exception</span> error)</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">{</span><br />
<div style="text-indent: 36pt;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">throw</span><span style="font-family: "consolas"; font-size: 9.5pt;"> error;</span></div>
<span style="font-family: "consolas"; font-size: 9.5pt;">}</span></td>
</tr>
</tbody>
</table>
<br />
<span style="color: orange;"><b>//Sending Mail Using Yahoo</b></span><br />
<table style="background-color: #d5d5ff;">
<tbody>
<tr>
<td><span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//send mail using yahoo idstring ToAddress = txtto.Text;</span> <br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">const</span><span style="font-family: "consolas"; font-size: 9.5pt;"> <span style="color: blue;">string</span> FromAddress = <span style="color: #a31515;">"your Yahoo id"</span>;<span style="color: green;">//For Example tejasvbhalani@yahoo.com</span></span><br />
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">string</span><span style="font-family: "consolas"; font-size: 9.5pt;"> Subject = txtsub.Text;</span><br />
<span style="color: #2b91af; font-family: "consolas"; font-size: 9.5pt;">String</span><span style="font-family: "consolas"; font-size: 9.5pt;"> Body = txtbody.Text;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">System.Net.Mail.<span style="color: #2b91af;">MailMessage</span> mail = <span style="color: blue;">new</span> System.Net.Mail.<span style="color: #2b91af;">MailMessage</span>();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">mail.To.Add(ToAddress);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">mail.From = <span style="color: blue;">new</span> MailAddress(FromAddress);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">mail.Subject = Subject;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">mail.Body = Body; client.Credentials = <span style="color: blue;">new</span> System.Net.<span style="color: #2b91af;">NetworkCredential</span>(FromAddress, <span style="color: #a31515;">"yahoo id password"</span>);</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">mail.Priority = System.Net.Mail.<span style="color: #2b91af;">MailPriority</span>.High;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">SmtpClient client = <span style="color: blue;">new</span> SmtpClient();</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">client.Port = 587;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">client.Host = <span style="color: #a31515;">"smtp.mail.yahoo.com"</span>;</span><br />
<span style="font-family: "consolas"; font-size: 9.5pt;">client.Send(mail);</span></td>
</tr>
</tbody>
</table>
<br />
Use Code For Send Mail to any emailid...........
</div>Dot Net Expertshttp://www.blogger.com/profile/05035262148501393307noreply@blogger.com1