Saturday, April 20, 2013

How to Remove Css Style from codebehind?

Here is how we can achieve this from codebhind in c#. Here is the sample code snippet I am here removing CssSytle from DIV but I works for any Control

   1: // Removing Div class when we have only transaction details
   2: divTransactionSummary.Attributes.Add("class", divTransactionSummary.Attributes["class"].ToString().Replace("prodiv", ""));
   3:               

Here “prodiv” is the class of div I have used in my aspx page for this DIV


Hope this helps!!

Sunday, March 31, 2013

iPad Supported Video Formats

I got my first iPad and I am trying to know about that are the Video formats that are supported by iPad devices.

Here is the list

  • H.264 video up to 720p, 30 frames per second, Main Profile level 3.1 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats.
  • MPEG-4 video, up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps per channel, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats.
  • Motion JPEG (M-JPEG) up to 35 Mbps, 1280 by 720 pixels, 30 frames per second, audio in ulaw, PCM stereo audio in .avi file format.

I found this information via google. Thought this worth sharing.

Saturday, March 23, 2013

SMTP Server Error: Bad sequence of commands. The server response was: you must authenticate first (#5.5.1)

This error occurs due to lock down of default mail server (127.0.0.1) by web hosting companies due to SPAM or what ever other security reasons. But if you use “localhost” or default server “127.0.0.1” on your local machine it should not be an issue. But if you have a situation where you need to relay e-mail to a remote mail server that is secured you get this exception.

So you need to handle well using built in classes provided by .NET. This is take care by NetworkCredential Class. This class provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication.

Here is a fully working quick code sample that you can use to get started on your own SMTP-Authentication supporting e-mail code.

   1: try
   2: {
   3:     SmtpClient smtpclient = new SmtpClient();
   4:     NetworkCredential NetworkCredential = new NetworkCredential(smtpUserName, smtpPassword);
   5:     smtpclient.Credentials = NetworkCredential;
   6:     string MailServer = ConfigurationManager.AppSettings["SMTPServer"].ToString();
   7:     MailMessage objEmail = new MailMessage();
   8:  
   9:     string FromEmail = ConfigurationManager.AppSettings["ErrorReportEmailFrom"].ToString();
  10:     if (FromEmail.IndexOf(";") > 0)
  11:     {
  12:         FromEmail = FromEmail.Replace(";", ",");
  13:     }
  14:     MailAddress FromAddress = new MailAddress(FromEmail);
  15:     objEmail.From = FromAddress;
  16:  
  17:     string ToEmail = ConfigurationManager.AppSettings["ErrorReportEmailTo"].ToString();
  18:     if (ToEmail.IndexOf(";") > 0)
  19:     {
  20:         ToEmail = ToEmail.Replace(";", ",");
  21:     }
  22:     objEmail.To.Add(ToEmail);
  23:  
  24:     string CcEmail = ConfigurationManager.AppSettings["CcEmail"].ToString();
  25:     if (CcEmail.IndexOf(";") > 0)
  26:     {
  27:         CcEmail = CcEmail.Replace(";", ",");
  28:     }
  29:     objEmail.CC.Add(CcEmail);
  30:  
  31:     string BccEmail = ConfigurationManager.AppSettings["BccEmail"].ToString();
  32:     if (BccEmail.IndexOf(";") > 0)
  33:     {
  34:         BccEmail = BccEmail.Replace(";", ",");
  35:     }
  36:     objEmail.Bcc.Add(BccEmail);
  37:  
  38:     objEmail.Subject = strSubject;
  39:     try
  40:     {
  41:         objEmail.Body = strBody;
  42:         objEmail.IsBodyHtml = true;
  43:         smtpclient.Host = MailServer;
  44:         smtpclient.Send(objEmail);
  45:     }
  46:     catch (Exception ex)
  47:     {
  48:         throw ex;
  49:     }
  50:     finally
  51:     {
  52:         objEmail.Dispose();
  53:     }
  54: }
  55: catch (Exception ex)
  56: {
  57:      
  58: }

Enjoy coding!!

Saturday, February 23, 2013

Select all user defined tables from database – SQL SERVER

There are different ways to select all User defined tables from databases

Option 1: Using Object Catalog view

   1: SELECT sobjects.name 
   2: FROM sysobjects sobjects
   3: WHERE sobjects.xtype = 'U'
   4: order by sobjects.name

Alternatively here is a list of other object types you can search for as well:


C: Check constraint
D: Default constraint
F: Foreign Key constraint
L: Log
P: Stored procedure
PK: Primary Key constraint
RF: Replication Filter stored procedure
S: System table
TR: Trigger
U: User table
UQ: Unique constraint
V: View
X: Extended stored procedure


Option 2: Using Information schema view



   1: SELECT * FROM INFORMATION_SCHEMA.TABLES 
   2: WHERE TABLE_TYPE = 'BASE TABLE'

Here is something you can do as well



   1: select * from sys.tables

Suppose you might need to get all tables from your SQL SERVER Instance. Here is what you can do



   1: --for all databases
   2: sp_msforeachdb 'select "?" AS db, * from [?].sys.tables'

Sunday, February 17, 2013

How to Set default button from C# to a Content Page

Here is how we can use default button property of the form to set Default Button for a content page from Code behind using C#
 
// Setting default button
this.Master.Page.Form.DefaultButton = this.btnSubmit.UniqueID;
 
Here is how we can set default button for the page which doesn’t have Master Page
// Setting Default Button           
this.Page.Form.DefaultButton = btnSubmit.UniqueID;
 
Hope this helps!!