using System; using System.Xml; using System.Text;
public class MainClass { public static void Main(string [] arg) { // To create an Xml file with the following format // <?xml version="1.0" encoding="Windows-1252" standalone="yes"?> // <directory> // <files dir="c:\" /> // </directory>
XmlTextWriter xmlText = new XmlTextWriter("filename.xml", Encoding.Default);
xmlText.Formatting = Formatting.Indented;
xmlText.WriteStartDocument(true);
// If you want to attach an Xsl file with the Xml then uncomment the following 2 lines // It actually adds the xml-stylesheet attribute // string xslText="type='text/xsl' href='../index.xsl'"; // xmlText.WriteProcessingInstruction("xml-stylesheet", xslText);
The PageCapturer utility is used to download Web pages programmatically and save them onto hard disk.
File: PageCapturer.zip attached with this email.
Purpose:
I made this to help me organize the pages visited everyday into a separate directory. And through this way I can save each page automatically with out having to Save each file manually.
Feature Missing:
This utility only downloads the Text of the Web page, the images or other media linked is not downloaded.
ScreenShot:
Working:
You can either enter the link into the Link field and then press "Get Page" button or simply copy the url. The program checkes every 2 seconds for any url on the clip board. Currenly, only http:// and ftp:// files are supported.
When the page is downloaded completely, the link for the page is automatically added to the "List of Pages fetched today". The list is also saved as an xml file "index.xml" into each directory which is also loaded at the startup. The "View Index" button displays the "index.xml" file after transforming it with the xsl file "index.xsl". Whereas, the "View Page" button displays the selected page in the list. You can also view the page by double clicking the page on the list.
The code is simple and does not block from throwing any exception, therefore you might see some exceptions.
How-To Run:
Either load the solution into VS.NET and execute; or run the PageCapturer.exe in the bin\debug\ directory.
/regards,
Nauman Leghari
For any questions on this, email on laghari78@... :).
// capture webpage by using HttpWebRequest class and Save into file. File is saved in a separate directory for each day. Please check out the method to create directory daywise.
MSN Alerts Service is a part of Microsoft .NET My Services Initiative. It enables the service provider to reach its users through Instant Messages. Note that it will work on any type of devices, either mobile or desktops.
List some example applications?
1)Event Management Application: Notifies the user instantly of the event it registers.
2)Order Tracking Application: User is instantly notified if any change occurred in the order status.
Etc. etc.
So, where can you find the SDK? Licensing?
The MSN Alert SDK is downloaded for free from the following URL.
It also contains necessary licensing agreement information as MSN Alerts service in the production setup is not free of cost.
Building our Hello World MSN Alert Application:
The following listing demonstrates a sample Console Application for MSN Alerts. For all the classes, properties and methods involved in the sample, consult the SDK documentation. Note that you need to Add Reference to the Microsoft Notification SDK Type Library (msnotify.dll). This COM Component is automatically registered when you install the Developer’s SDK.
<code>
using System;
using System.Reflection;
using System.Runtime.InteropServices;
// the following namespace is automatically added when you add a
// reference to the Microsoft Notifications SDK Type Library. Because the
// MSN Alerts subsystem is built using COM therefore we need the
// System.Runtime.InteropServices to access the COM objects through
Here is an example of advanced Numeric Format Specifier , according to exact position of numerals
' Change the number to Telephone number format
'///////////////
Dim Mynumber As Double = 1234567890
Dim MyString As String = Mynumber.ToString("(###) ### - ####")
'///////////////
and the output is (123) 456 – 7890
------------------------------------------------
Further Details of advanced Numeric Format Specifiers are following:
Format character
Name
Description
0
Zero placeholder
If the value being formatted has a digit in the position where the '0' appears in the format string, then that digit is copied to the output string. The position of the leftmost '0' before the decimal point and the rightmost '0' after the decimal point determines the range of digits that are always present in the output string.
#
Digit placeholder
If the value being formatted has a digit in the position where the '#' appears in the format string, then that digit is copied to the output string. Otherwise, nothing is stored in that position in the output string. Note that this specifier never displays the '0' character if it is not a significant digit, even if '0' is the only digit in the string. It will display the '0' character if it is a significant digit in the number being displayed.
.
Decimal point
The first '.' character in the format string determines the location of the decimal separator in the formatted value; any additional '.' characters are ignored. The actual character used as the decimal separator is determined by the NumberDecimalSeparator property of the NumberFormatInfo object that controls formatting.
,
Thousand separator and number scaling
The ',' character serves two purposes. First, if the format string contains a ',' character between two digit placeholders (0 or #) and to the left of the decimal point if one is present, then the output will have thousand separators inserted between each group of three digits to the left of the decimal separator. The actual character used as the decimal separator in the output string is determined by the NumberGroupSeparator property of the current NumberFormatInfo object that controls formatting.
Second, if the format string contains one or more ',' characters immediately to the left of the decimal point, then the number will be divided by the number of ',' characters multiplied by 1000 before it is formatted. For example, the format string '0,,' will represent 100 million as simply 100. Use of the ',' character to indicate scaling does not include thousand separators in the formatted number. Thus, to scale a number by 1 million and insert thousand separators you would use the format string '#,##0,,'.
%
Percentage placeholder
The presence of a '%' character in a format string causes a number to be multiplied by 100 before it is formatted. The appropriate symbol is inserted in the number itself at the location where the '%' appears in the format string. The percent character used is dependent on the current NumberFormatInfo class.
E0
E+0
E-0
e0
e+0
e-0
Scientific notation
If any of the strings 'E', 'E+', 'E-', 'e', 'e+', or 'e-' are present in the format string and are followed immediately by at least one '0' character, then the number is formatted using scientific notation with an 'E' or 'e' inserted between the number and the exponent. The number of '0' characters following the scientific notation indicator determines the minimum number of digits to output for the exponent. The 'E+' and 'e+' formats indicate that a sign character (plus or minus) should always precede the exponent. The 'E', 'E-', 'e', or 'e-' formats indicate that a sign character should only precede negative exponents.
\
Escape character
In C# and the Managed Extensions for C++, the backslash character causes the next character in the format string to be interpreted as an escape sequence. It is used with traditional formatting sequences like "\n" (new line).
In some languages, the escape character itself must be preceded by an escape character when used as a literal. Otherwise, the compiler interprets the character as an escape sequence. Use the string "\\" to display "\".
Note that this escape character is not supported in Visual Basic; however, ControlChars provides the same functionality.
'ABC'
"ABC"
Literal string
Characters enclosed in single or double quotes are copied to the output string literally, and do not affect formatting.
;
Section separator
The ';' character is used to separate sections for positive, negative, and zero numbers in the format string.
Other
All other characters
All other characters are copied to the output string as literals in the position they appear.
Example of the most Common Decimal Numeric Format.
'Insert Commas after each thousand , with specified number of decimal precision.
'////////////////
Dim var As Decimal = 12454545.340456
txt_messages.Text = var.ToString("N8") ' Where8 is the number of digits we want to display after decimal.
'////////////////
the Output is
12,454,545.34045600
In Output its clearly seen that our format specifier has inserted 2 0s to make the number of digits 8 after decimal AND also has inserted commas after Each Thousand.
The number is converted to a string that represents a currency amount. The conversion is controlled by the currency format information of the NumberFormatInfo object used to format the number. The precision specifier indicates the desired number of decimal places. If the precision specifier is omitted, the default currency precision given by the NumberFormatInfo is used.
D or d
Decimal
This format is supported for integral types only. The number is converted to a string of decimal digits (0-9), prefixed by a minus sign if the number is negative. The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier.
E or e
Scientific (exponential)
The number is converted to a string of the form "-d.ddd…E+ddd" or "-d.ddd…e+ddd", where each 'd' indicates a digit (0-9). The string starts with a minus sign if the number is negative. One digit always precedes the decimal point. The precision specifier indicates the desired number of digits after the decimal point. If the precision specifier is omitted, a default of six digits after the decimal point is used. The case of the format specifier indicates whether to prefix the exponent with an 'E' or an 'e'. The exponent always consists of a plus or minus sign and a minimum of three digits. The exponent is padded with zeros to meet this minimum, if required.
F or f
Fixed-point
The number is converted to a string of the form "-ddd.ddd…" where each 'd' indicates a digit (0-9). The string starts with a minus sign if the number is negative. The precision specifier indicates the desired number of decimal places. If the precision specifier is omitted, the default numeric precision given by the NumberFormatInfo is used.
G or g
General
The number is converted to the most compact decimal form, using fixed or scientific notation. The precision specifier determines the number of significant digits in the resulting string. If the precision specifier is omitted, the number of significant digits is determined by the type of number being converted:
Int16 or UInt16: 5 digits
Int32 or UInt32: 10 digits
Int64 or UInt64: 19 digits
Single: 7 digits
Double: 15 digits
Decimal: 29 digits
Trailing zeros after the decimal point are removed, and the resulting string contains a decimal point only if required.
The resulting string uses fixed-point format if the exponent of the number (as produced by the 'E' format) is less than the number of significant digits, and greater than or equal to –4. Otherwise, the resulting string uses scientific format, and the case of the format specifier controls whether the format is prefixed with an 'E' or an 'e'.
N or n
Number
The number is converted to a string of the form "-d,ddd,ddd.ddd…", where each 'd' indicates a digit (0-9). The string starts with a minus sign if the number is negative. Thousand separators are inserted between each group of three digits to the left of the decimal point. The precision specifier indicates the desired number of decimal places. If the precision specifier is omitted, the default numeric precision given by the NumberFormatInfo is used.
P or p
Percent
The number is converted to a string that represents a percent as defined by the NumberFormatInfo.PercentNegativePattern property or the NumberFormatInfo.PercentPositivePattern property. If the number is negative, the string produced is defined by the PercentNegativePattern and starts with a minus sign. The converted number is multiplied by 100 in order to be presented as a percentage. The precision specifier indicates the desired number of decimal places. If the precision specifier is omitted, the default numeric precision given by NumberFormatInfo is used.
R or r
Round-trip
The round-trip specifier guarantees that a numeric value converted to a string will be parsed back into the same numeric value. When a numeric value is formatted using this specifier, it is first tested using the general format, with 15 spaces of precision for a Double and 7 spaces of precision for a Single. If the value is successfully parsed back to the same numeric value, then it is formatted using the general format specifer. However, if the value is not successfully parsed back to the same numeric value, then the value is formatted using 17 digits of precision for a Double and 9 digits of precision for a Single. Although a precision specifier can be appended to the round-trip format specifier, it is ignored. Round trips are given precedence over precision when using this specifier. This format is supported by floating-point types only.
X or x
Hexadecimal
The number is converted to a string of hexadecimal digits. The case of the format specifier indicates whether to use uppercase or lowercase characters for the hexadecimal digits greater than 9. For example, use 'X' to produce 'ABCDEF', and 'x' to produce 'abcdef'. The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier. This format is supported for integral types only.
A Typical Socket Server -Steps: 1: Create a TcpListener Object 2: Call Start Method of TcpListener Object (Now the server actually starts looking for any client connection. 3: To Receive the requesting Client Connection, Call AcceptSocket Method of TcpListner Object,It actually returns a socket(TcpClient) object. This is where you can start the communication (send/receive bytes) with the client. The is a Blocking method, you cant do anything after executing this method but communication with the client. You cant receive any other client connection and no other processing. 4: Processing Phase , Use Read and Write methods of networkstream object to communicate with the client. 5: When the client and server have finished communicating, the server closes the connection,Close method of socket (TcpClient) object. Most Servers will then go back to step number 3 and call AcceptSocket method to recive any new socket client connection.
One Problem associated with this scheme is that the step 4 blocks other requests while processing a client's request, so that no other client can connect with the server while the code that defines the processing phase is executing. The most common technique for addressing this problem is to use Multithreaded servers, which place the processing phase code in a seperate threadWhen a Server receives a connection request, the server spawns, or creates, a Thread to process the connection, leaving its TcpListener free to receive other connections.
Example of a simple Multithreaded Server can be found in Part II of this Article.
<WebMethod()> _ Public Function InchesToCentimeters(decInches As Decimal) As Decimal Return decInches * 2.54 End Function
<WebMethod()> _ Public Function CentimetersToInches(decCentimeters As Decimal) As Decimal Return decCentimeters / 2.54 End Function
<WebMethod()> _ Public Function MilesToKilometers(decMiles As Decimal) As Decimal Return decMiles * 1.61 End Function
<WebMethod()> _ Public Function KilometersToMiles(decKilometers As Decimal) As Decimal Return decKilometers / 1.61 End Function
End Class '////Code ends here
The simple classs in above code has 4 public functions. Each funtions is taking a parameter in and returning the converted result.
To consume the service from ASP.NET pages you have to perform the following steps
1: Its is assumed that you have already created the webservice (.asmx) file and it is located somewhere on the web (always accessable through http,either local or remote)
2. Now Create a proxy class for the webservice in question through the following command.
Following piece of code establishes a socks based connection to any server (localhost in this case) as port 13, If at port 13 there is some socks listner running to accept this connection, no error will appear and connection will be established correctly. else the code throws an exception saying no listener found at the specified address.Using this code u can connect to any socket server waiting for tcp socks connection. The code prints the welcome message from socket listner to the the console and sends the welcome message from itself as well.
Implement the OnItemCreated event for the datagrid.
Then set
System.Web.UI.WebControls.DataGridItemEventArgs.Item.Cells[<columnno>].W
idth = <width>
private void dGrid_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Cells[0].Width = 270;
}
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data.OleDb; using System.Configuration;
namespace Problems { /// <summary> /// Summary description for PRowColor. /// </summary> public class PRowColor : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid dGrid; protected System.Web.UI.WebControls.Label lblStatus;
private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here // Put user code to initialize the page here OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
string strSql = "select PubId,Name,Address,City from Publishers";
OleDbCommand myCommand = new OleDbCommand(strSql,myConnection);
override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.dGrid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dGrid_ItemDataBound); this.Load += new System.EventHandler(this.Page_Load);
}
private void dGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { // only apply on item and alternating item if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // getting the index value ( or any other data cell value ) string sVal = e.Item.Cells[0].Text;
// changing the color or all even rows if ((Convert.ToInt32(sVal)%2) == 0) { // changing color for individial row e.Item.BackColor = System.Drawing.Color.Red;
// changing color for individual column e.Item.Cells[0].BackColor = System.Drawing.Color.Green; } } } } }
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data.OleDb; using System.Configuration;
namespace Problems { /// <summary> /// Summary description for PRowColor. /// </summary> public class PRowColor : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid dGrid; protected System.Web.UI.WebControls.Label lblStatus; int itemCount = 0;
private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here // Put user code to initialize the page here OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
string strSql = "select PubId,Name,Address,City from Publishers";
OleDbCommand myCommand = new OleDbCommand(strSql,myConnection);
override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.dGrid.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dGrid_ItemCreated); this.Load += new System.EventHandler(this.Page_Load);
}
private void dGrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { // test: calculating how many times the ItemCreated event is called itemCount ++; lblStatus.Text += " " + itemCount.ToString();
// only apply on item and alternating item if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string sVal = e.Item.Cells[0].Text; lblStatus.Text += " " + sVal;
// changing color of whole column e.Item.Cells[2].BackColor = System.Drawing.Color.Red; } } } }