Friday, November 28, 2008
How to Use an XPath on a DataSet
Here are the used classes:
DataRow
DataSet
XmlDataDocument
XmlNodeList
XmlNode
Here's the XML file:
<?xml version="1.0" encoding="utf-8"?>
<CategoryList>
<Category ID="01">
<Title>One</Title>
</Category>
<Category ID="03">
<Title>Three</Title>
</Category>
<Category ID="04">
<Title>Four</Title>
</Category>
<Category ID="02">
<Title>Two</Title>
</Category>
</CategoryList>
Finally, here's the code:
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("file.xml"));
XmlDataDocument xmlDoc = new XmlDataDocument(ds);
XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("/CategoryList/Category[@ID=01]");
DataRow myRow;
foreach (XmlNode myNode in nodeList)
{
myRow = xmlDoc.GetRowFromElement((XmlElement)myNode);
if (myRow != null)
Response.Write(myRow[0]);
}
How to get the detail associated with the current user using C# (.NET)
String sFile;
sFile = Path.GetTempFileName();
Console.WriteLine("Temporary File " + sFile);
//Store the Values Temporarily in Temp file
StoreVar(sFile);
Temporary folders Name
string sPath;
sPath = Path.GetTempPath();
Console.WriteLine("Temporary Path := " + sPath );
IsPathRooted method of Path class returns a value indicating whether the specified path string contains absolute or relative path information
if (Path.IsPathRooted(@"c:\temp\") == true)
{
Console.WriteLine("Path is absolute");
}
else
{
Console.WriteLine("Path is relative");
}
To retrieve the logical MyDocuments use the following
Console.WriteLine("MyDocuments := " + Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments));
To retrieve the logical desktop use the following
Console.WriteLine("Desktop := " + Environment.GetFolderPath( Environment.SpecialFolder.Desktop));
Cookies folder (FullName) can be retrieved using the following snippet
Console.WriteLine("Cookies := " + Environment.GetFolderPath( Environment.SpecialFolder.Cookies ));
ApplicationData is the directory that serves as a common repository for application-specific data for the current roaming user. It can be retrieved using
Console.WriteLine("ApplicationData := " + Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData));
How to get the network domain name associated with the current user using C# (.NET)
Console.WriteLine("Domain Name := " + Environment.UserDomainName );
No of processors in the given machine can be retrieved by
Console.WriteLine("ProcessorCount := " + Environment.ProcessorCount );
Retrieve user name using .NET / How to get user name using C#
The following code will get the user name of the computer
Console.WriteLine("User Name := " + Environment.UserName);
Get Computer Name using .NET (C#)
Console.WriteLine("Machine Name := " + Environment.MachineName);
Get all Sub Directories under a folder using C# (.NET)
Listing all subdirectories under a root directory using .NET (C#) is simple. You can use the DirectoryInfo..::.GetDirectories Method to list the directories
private static void ListDir(string rootdir)
{
try
{
DirectoryInfo[] DI = new DirectoryInfo(rootdir).GetDirectories("*.*", SearchOption.AllDirectories ) ;
foreach (DirectoryInfo D1 in DI)
{
Console.WriteLine(D1.FullName);
}
}
catch (DirectoryNotFoundException dEX)
{
Console.WriteLine("Directory Not Found " + dEX.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Here is the overload list of GetDirectories method
Name
Description
GetDirectories()()()
Returns the subdirectories of the current directory.
GetDirectories(String)
Returns an array of directories in the current DirectoryInfo matching the given search criteria.
GetDirectories(String, SearchOption)
Returns an array of directories in the current DirectoryInfo matching the given search criteria and using a value to determine whether to search subdirectories.
C# GetDirectories()()() Method, C# GetSubDirectories Method, Dir Function in VB.NET, Dir Function in C#, List All Directories using C#, List Sub Directories using C#, How to get all subdirectories using C#
.NET GetDirectories()()() Method, .NET GetSubDirectories Method, Dir Function in VB.NET, Dir Function in .NET, List All Directories using .NET, List Sub Directories using .NET, How to get all subdirectories using .NET
Get Size of a Particular Directory using C# (.NET)
One way to find the size of entire directory (including all sub-directories) is to sum up the size of all files in those directories
The following code snippet adds the size of all the files to get the directory size
private static void GetDirSize(string rootdir)
{
try
{
long DirSize = 0;
DirectoryInfo[] DI = new DirectoryInfo(rootdir).GetDirectories("*.*", SearchOption.AllDirectories);
FileInfo[] FI = new DirectoryInfo(rootdir).GetFiles("*.*", SearchOption.AllDirectories);
foreach (FileInfo F1 in FI)
{
DirSize += F1.Length;
}
Console.WriteLine("Total Size of {0} is {1} bytes", rootdir, DirSize);
}
catch (DirectoryNotFoundException dEX)
{
Console.WriteLine("Directory Not Found " + dEX.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Get Directory Size using C#, Get SubDirectory Size using C#, SearchOption.AllDirectories in C#, How to Search All Directories using C#, FileSize using C#, How to get directory size using C#
Get Directory Size using .NET, Get SubDirectory Size using .NET, SearchOption.AllDirectories in .NET, How to Search All Directories using .NET, FileSize using .NET, How to get directory size using .NET
Converting Date to British Date Format using C# (.NET)
Formatting dates are easy in C#. The following snippet gets the current date in British format.
private static string ConvertDate2British()
{
return String.Format("{0:dd-MM-yy}", DateTime.Now);
}
How to convert dates to British format using .NET, Date Conversion using .NET, .NET String.Format Method, Get Current Date using .NET, .NET Today Method
See also:
Formatting Date Input - DateFOrmat (SQL
Some Blogger id
Some Blogger id
send mail
public void SendMail()
{
//Builed The MSG
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(txtemail.Text);
// msg.To.Add("1980dinesh@gmail.com");
msg.From = new MailAddress("dinesh.kumar@mobilex.in", "Friends Invitaion", System.Text.Encoding.UTF8);
msg.Subject = "Frineds";
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = "Hi" ;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;
//Add the Creddentials
SmtpClient client = new SmtpClient();
//client.UseDefaultCredentials = false;
//client.Credentials = new System.Net.NetworkCredential("dinesh.kumar@mobilex.in", "dinesh08");
//client.Port = 587;//or use 587
//client.Host = "smtp.gmail.com";
client.EnableSsl = true;
try
{
client.Send(msg);
//you can also call client.Send(msg)
}
catch (System.Net.Mail.SmtpException ex)
{
}
}
<appSettings/>
<system.net>
<mailSettings>
<smtp>
<network host="smtp.gmail.com" port="587" userName="suresh.chandra@swaransoft.com" password="xyz"/>
</smtp>
</mailSettings>
</system.net>
Send mail in asp.net
{
try
{
MailMessage message = new MailMessage();
message.From = new MailAddress("subudhi.suresh@gmail.com");
message.To.Add(new MailAddress("subudhi.suresh@gmail.com"));
message.Subject = "test"; // sets the subject property of message
message.Body ="hi"; // sets the body for the message
//message.Priority = MailPriority.High;
message.IsBodyHtml = false;
SmtpClient client = new SmtpClient("smtp.googlemail.com", 587);
System.Net.NetworkCredential basicAuthentication = new System.Net.NetworkCredential("suresh.chandra@swaransoft.com", "chandra08");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
//Put your own, or your ISPs, mail server name onthis next line
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = basicAuthentication;
client.Send(message);
//return true;
}
catch(Exception ex) { }
}
Tuesday, November 25, 2008
video in asp.net
< param name="FileName" value="< %=s %>">
< %--< param name="AutoRewind" value="true">
< param name="AutoStart" value="false">
< param name="ClickToPlay" value="true">
< param name="Mute" value="false">
< param name="ShowControls" value="true">
< param name="ShowDisplay" value="true">
< param name="ShowTracker" value="true">
< param name="PlayCount" value="1">--%>
< EMBED type="video/x-ms-wmv" width="416px" height="320px" autostart="true" src="< %=s %>" URL=".\video\193.mpg" enabled="True" balance="0" currentPosition="0" enableContextMenu="True" fullScreen="False" mute="False" playCount="1" rate="1" stretchTofit="False" uiMode="3" >
< /embed>
< /object>-
Tuesday, November 18, 2008
how to send sms to mobile in asp.net(C#)
Visit this might shed a light on it.
http://www.ozekisms.com/index.php?owpn=230
http://www.smsxchange.com/main/default.asp
It also has been discussed here.
http://forums.asp.net/t/1193672.aspx
1. First of all you should have the SMS Package for sending SMS
2. Suppose if you've then right click on application in VS and select Add Web Referrence...
3. You've to add this in Web Config AppSettings
add this in u r code or you can customize in your own way
private bool SendSms(string mobileNo)
{
try
{
mobileNo = "Internation Code 1" + mobileNo.Substring(1, mobileNo.Length - 1);
BulkSingleSend mySms = new BulkSingleSend();
Boolean ServiceStatus = mySms.IsServiceAlive();
string smsBody = System.Configuration.ConfigurationManager.AppSettings["smsbody"].ToString();
string result = mySms.SendSMS("From", "Subject", mobileNo.Text, TextBox1.Text);
return true;
}
catch
{
return false;
}
}
Note: When you add Web Referrence in your Application you'll find three new files with extention .disco, .wsdl, .discomap extention files.
private void Send_Click(
object sender, System.EventArgs e)
{
try
{
SmsTest.net.webservicex.www.SendSMS smsIndia=
new SmsTest.net.webservicex.www.SendSMS();
SmsTest.com.webservicex.www.SendSMSWorld smsWorld =
new SmsTest.com.webservicex.www.SendSMSWorld();
if(rdoType.SelectedValue == "1")
smsIndia.SendSMSToIndia(txtMobileNo.Text.Trim(),
txtEmailId.Text.Trim(), txtMessage.Text);
else
smsWorld.sendSMS(txtEmailId.Text.Trim(),
txtCountryCode.Text.Trim(), txtMobileNo.Text.Trim(),
txtMessage.Text);
lblMessage.Visible = true;
lblMessage.Text="Message Send Succesfully";
}
catch(Exception ex)
{
lblMessage.Visible = true;
lblMessage.Text="Error in Sending message"+ex.ToString();
}
}
Sunday, November 16, 2008
Great articles on Data Structures and Collections in .NET
I would recommend reading these below mentioned articles from MSDN for any programmer who wants to develop or is developing using Microsoft .NET Framework technologies.
Part 1: An Introduction to Data Structures
Part 2: The Queue, Stack, and Hashtable
Part 3: Binary Trees and BSTs
Part 4: Building a Better Binary Search Tree
Part 5: From Trees to Graphs
Part 6: Efficiently Representing Sets
Posted by chirag at 6:27 PM 0 comments
Labels: .NET Concepts, .NET Examples, .NET Framework, C# .NET, VB .NET
Data Structures in .NET
Why data structures are important, and their effect on the performance of an algorithm. To determine a data structure's effect on performance, we'll need to examine how the various operations performed by a data structure can be rigorously analyzed. Finally, we'll turn our attention to two similar data structures present in the .NET Framework: the Array and the List. Chances are you've used these data structures in past projects. In this article, we'll examine what operations they provide and the efficiency of these operations.
The Queue and Stack. Like the List, both the Queue and Stack store a collection of data and are data structures available in the .NET Framework Base Class Library. Unlike a List, from which you can retrieve its elements in any order, Queues and Stacks only allow data to be accessed in a predetermined order. We'll examine some applications of Queues and Stacks, and see how these classes are implemented in the .NET Framework. After examining Queues and Stacks, we'll look at hashtables, which allow for direct access like an ArrayList, but store data indexed by a string key.
While arrays and Lists are ideal for directly accessing and storing contents, when working with large amounts of data, these data structures are often sub-optimal candidates when the data needs to be searched. The binary search tree data structure, which is designed to improve the time needed to search a collection of items. Despite the improvement in search time with the binary tree, there are some shortcomings. SkipLists, which are a mix between binary trees and linked lists, and address some of the issues inherent in binary trees.
A graph is a collection of nodes, with a set of edges connecting the various nodes. For example, a map can be visualized as a graph, with cities as nodes and the highways between them as edged between the nodes. Many real-world problems can be abstractly defined in terms of graphs, thereby making graphs an often-used data structure.
Finally, in Part 6 we'll look at data structures to represent sets and disjoint sets. A set is an unordered collection of items. Disjoint sets are a collection of sets that have no elements in common with one another. Both sets and disjoint sets have many uses in everyday programs, which we'll examine in detail in this final part.
Part 1: An Introduction to Data Structures
Technorati Tags: Data Structures, C# .NET, .NET framework, ArrayList, .NET Collections
Posted by chirag at 10:01 AM 0 comments
Labels: .NET Concepts, .NET Framework, C# .NET
Creating / Writing XML Documents with the XmlTextWriter Class
The .NET Framework provides a class designed specifically to create XML documents, theSystem.Xml.XmlTextWriter class. By using this class to create XML documents you don't need to worry about illegal XML characters in the text portion of the XML document, and the end code is much cleaner. In this article we'll look at using the XmlTextWriter class to create XML documents on the fly.
The Basics of the XmlTextWriter Class
The XmlTextWriter class contains a number of methods that are useful for starting and completing an XML document and for adding elements and attributes to the XML document. The most important methods are:
- WriteStartDocument() - you should call this method to start creating an XML document. This will create the first line in the XML document, specifying that the file is an XML document and its encoding.
- WriteStartElement(string) - this method creates a new element in the XML document with the name specified by the string input parameter. (You can also specify a namespace as a second, optional string parameter.)
- WriteElementString(name, text_value) - If you want to create an XML element with nothing but text content (i.e., no nested elements), you can use this method.
- WriteAttributeString(name, value) - this method writes an attribute name and value to the current element.
- WriteEndElement() - this method closes off the element created in theWriteStartElement(string) method call.
- WriteEndDocument() - this method completes the writing of the XML document.
- Close() - this method closes the underlying stream, writing the contents of the XML document to the specified file location.
To get started using the XmlTextWriter class you need to specify the file and encoding in the class's constructor. The encoding needs to be of the type System.Text.Encoding; some example encoding values are: System.Text.Encoding.ASCII, System.Text.Encoding.Unicode, andSystem.Text.Encoding.UTF8. Alternatively, you can specify in the constructor that the output of the XmlTextWriter class should be squirted out to a specified Stream.
Creating a Simple XML Document with XmlTextWriter
To demonstrate using the XmlTextWriter class let's create a simple XML document, saving it to a specified file location. This XML document will contain information about the current user visiting the page, and will have this structure:
|
(This XML file structure was chosen so that it would illustrate using all of the XmlTextWritermethods discussed in the previous section.)
The code needed to create this XML document through an ASP.NET Web page is shown below:
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Text" %>
;"; |