==>There are three ways provided by Silverlight for layout.
(1) management Canvas
(2) Grid
(3) Stack panel
Each of these methodologies fit in to different situations as per layout needs.
All these layout controls inherit from Panel class.
Sunday, January 9, 2011
Why can’t we consume ADO.NET directly in SilverLight?
==> Below are the different ingredients which constitute SilverLight plugin.
One of the important points to be noted is that it does not consist of ADO.NET. In other words you can not directly call ADO.NET code from SilverLight application. Now the other point to be noted is that it has the WCF component. In other words you can call a WCF service.
In other words you can create a WCF service which does database operations and silverlight application will make calls to the same. One more important point to be noted is do not return ADO.NET objects like dataset etc because SilverLight will not be able to understand the same.
One of the important points to be noted is that it does not consist of ADO.NET. In other words you can not directly call ADO.NET code from SilverLight application. Now the other point to be noted is that it has the WCF component. In other words you can call a WCF service.
In other words you can create a WCF service which does database operations and silverlight application will make calls to the same. One more important point to be noted is do not return ADO.NET objects like dataset etc because SilverLight will not be able to understand the same.
Saturday, January 8, 2011
Zip/compress one file using Gzipstream
using System.Security.Cryptography;
private void button1_Click(object sender, EventArgs e)
{
// Path to file to compress and decompress.
string fpath = @"e:\hello.exe";
FileInfo f1 = new FileInfo(fpath);
Compress(fi);
string fpath2 = @"e:\hello.gz";
FileInfo f2 = new FileInfo(fpath2);
Decompress(f2);
}
public static void Compress(FileInfo fi)
{
// Get the stream of the source file.
using (FileStream inFile = fi.OpenRead())
{
// Prevent compressing hidden and
// already compressed files.
if ((File.GetAttributes(fi.FullName)
& FileAttributes.Hidden)
!= FileAttributes.Hidden & fi.Extension != ".gz")
{
// Create the compressed file.
using (FileStream outFile =
File.Create(fi.FullName + ".gz"))
{
using (GZipStream Compress =
new GZipStream(outFile,
CompressionMode.Compress))
{
// Copy the source file into
// the compression stream.
inFile.CopyTo(Compress);
Console.WriteLine("Compressed {0} from {1} to {2} bytes.",
fi.Name, fi.Length.ToString(), outFile.Length.ToString());
}
}
}
}
}
public static void Decompress(FileInfo fi)
{
// Get the stream of the source file.
using (FileStream inFile = fi.OpenRead())
{
// Get original file extension, for example
// "doc" from report.doc.gz.
string curFile = fi.FullName;
string origName = curFile.Remove(curFile.Length -
fi.Extension.Length);
//Create the decompressed file.
using (FileStream outFile = File.Create(origName))
{
using (GZipStream Decompress = new GZipStream(inFile,
CompressionMode.Decompress))
{
// Copy the decompression stream
// into the output file.
Decompress.CopyTo(outFile);
Console.WriteLine("Decompressed: {0}", fi.Name);
}
}
}
}
Send Email from asp.net
using System.Net.Mail;
String userName = "your username";
String passWord = "your password";
String sendr = "your email id";
String recer = "receiver of email";
String subject = "subject of email";
String body = "body part of email";
MailMessage msgMail = new MailMessage(sendr, recer, subject, body);
int PortNumber = 587; // port number
SmtpClient smtp = new SmtpClient("smtpservername", PortNumber);
msgMail.IsBodyHtml = true;
// if your body contains html tag
// if your body contains html tag
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential(userName, passWord);
try
{
smtp.Send(msgMail);
}
catch (Exception exp)
{
// error handling
}
Get am/pm from datetime in sql query
below query gives you the am/pm from table field "yourdate" and it gives in ascending order SELECT SUBSTRING(CONVERT(varchar(20), yourdate, 22), 18, 3) AS Expr1 FROM table ORDER BY expr1 ; SUBSTRING(CONVERT(varchar(20), yourdate, 22), 18, 3)-->it gives you a am/pm. o/p: ---- am pm am pm |
how to disable right click on images
this is script for disable right click on images for html pages.
<script language="JavaScript">
<script language="JavaScript">
var clickmessage="Right click disabled on images!"
function disableclick(e)
{
if (document.all)
{
if (event.button==2||event.button==3)
{
if (event.srcElement.tagName=="IMG")
{
alert(clickmessage);
return false;
}
}
}
else if (document.layers)
{
if (e.which == 3)
{
alert(clickmessage);
return false;
}
}
else if (document.getElementById)
{
if (e.which==3&&e.target.tagName=="IMG")
{
alert(clickmessage)
return false
}
}
}
function associateimages()
{
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}
if (document.all)
{
document.onmousedown=disableclick
}
else if (document.getElementById)
{
document.onmouseup=disableclick
}
else if (document.layers)
{
associateimages()
}
</script>
How to disable particular Day of a Week in ASP.Net Calendar control?
The below little code snippet will help you to do that by using DayRender event of Calendar control.
ASPX
<asp:Calendar ID="Calendar1" runat="server" ondayrender="Calendar1_DayRender"> </asp:Calendar>
CodeBehind
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date.DayOfWeek == DayOfWeek.Monday)
{
e.Day.IsSelectable = false;
}
}
ASPX
<asp:Calendar ID="Calendar1" runat="server" ondayrender="Calendar1_DayRender"> </asp:Calendar>
CodeBehind
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date.DayOfWeek == DayOfWeek.Monday)
{
e.Day.IsSelectable = false;
}
}
Subscribe to:
Posts (Atom)