h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

AS operator attempts to cast an object to a specified type

–returning the instance cast to the type
–null if not possible
–does not raise an exception

COM object that has been separated from its underlying RCW cannot be used

COM object that has been separated from its underlying RCW cannot be used. Error occured when i closed the application in C#.net
How to fix it?


 I am using event watcher in my Application . So I didn't stop when i close the Application ,So I Stop eventWatcher. solved issue

Update auto_increment in SQL Server

Update auto_increment in SQL Server

Create PROC SP_UpdateEmployee @Id int = null out, @employeename varchar(50), @Active bit AS INSERT INTO Employeemaster(employeename,Active)values(@employeename,@Active) Set @Id = Scope_Identity()

Get Count of Unread mail from Outlook Express in C#.Net

Get Count of Unread mail from Outlook Express in C#.Net

 using Microsoft.Office.Interop.Outlook;  
   public static int CountOfUnreadMails()  
     {  
       Application OutlookApp = new Application();  
       NameSpace myMail = OutlookApp.GetNamespace("MAPI");  
       int unread = myMail.GetDefaultFolder(OlDefaultFolders.olFolderInbox).UnReadItemCount;  
      return  unread;  
      }  

Upload Single file to FTP Server using C#.net

Upload Single file to FTP Server using C#.net

  public static bool UploadSingleFiles(string fileName,int candidateId,int resumeId)  
     {  
       try  
       {  
         string parentDir = string.Empty;  
         string candir = string.Empty;  
         string desPath = string.Empty;  
         FileInfo objfileInfo = new FileInfo(fileName);  
         parentDir = ClsConfigurations.ReadSetting("Folder");  
         candir = @"/" + parentDir + "/" + Convert.ToString(candidateId);  
         desPath = candir +"-" + Convert.ToString(resumeId) + objfileInfo.Extension;  
         CreateDirectory(candir);  
         objFTPCon.ServerDirectory = candir.Trim();  
         objFTPCon.UploadFile(fileName, desPath);  
         return true;  
       }  
       catch (Exception ex)  
       {  
         Program.WriteLog(ex.Message, ex.StackTrace);  
         return false;  
       }  
     }  

UnCheck All Checked List Box in C#.net

UnCheck All Checked List Box in C#.net
public static void UnCheckedAllChecks(CheckedListBox chkLstBox) { foreach (int i in chkLstBox.CheckedIndices) { chkLstBox.SetItemCheckState(i, CheckState.Unchecked); } }

TextBox Error Provider for Tab Page in C#.net

TextBox Error Provider for Tab Page in C#.net
public static bool TextBoxErrorControl(TextBox txt, string message,TabPage tp)
{
if (!string.IsNullOrEmpty(txt.Text))
{
ErrProvider.SetError(txt, "");
}
else
{
ErrProvider.SetError(txt, message);
}
object[] control = ErrProvider.GetControls(tp).ToArray();
if (control.Length > 0)
return false;
else
return true;
}

Set DefaultIntValue in C#.net

Set DefaultIntValue in C#.net
public static int DefaultIntValue(TextBox txt)
{
try
{
if (String.IsNullOrEmpty(txt.Text))
{
return 0;
}
else
{
return Convert.ToInt32(txt.Text);
}
}
catch (Exception ex)
{
Program.WriteLog(ex.Message, ex.StackTrace);
return 0;
}
}

DefaultDoubleValue on TextBox in C#.net

DefaultDoubleValue on TextBox in C#.net
public static Double DefaultDoubleValue(TextBox txt)
{
try
{
if (String.IsNullOrEmpty(txt.Text))
{
return 0.00;
}
else
{
return Convert.ToDouble(txt.Text);
}
}
catch (Exception ex)
{
Program.WriteLog(ex.Message, ex.StackTrace);
return 0.00;
}
}

ComboBox With Error Provider in C#.net

ComboBox With Error Provider in C#.net


Create CustomError Provider in your project
 using System.Collections.Generic;  
 using System.Windows.Forms;  
 namespace naraayananProject.UserControl  
 {  
   public class CustomErrorProvider :ErrorProvider   
   {  
     public List<Control> GetControls()  
     {  
       return this.GetControls(this.ContainerControl);  
     }  
     public List<Control> GetControls(Control ParentControl)  
     {  
       List<Control> ret = new List<Control>();  
       if (!string.IsNullOrEmpty(this.GetError(ParentControl)))  
         ret.Add(ParentControl);  
       foreach (Control c in ParentControl.Controls)  
       {  
         List<Control> child = GetControls(c);  
         if (child.Count > 0)  
           ret.AddRange(child);  
       }  
       return ret;  
     }  
   }  
 }  

Declare Custom Error Provider in your Current Class:
 public static CustomErrorProvider ErrProvider = new CustomErrorProvider();  

  public static bool ComboBoxErrorControl(ComboBox cmb, string message, TabPage tp)  
     {  
       if (!String.IsNullOrEmpty(cmb.Text))  
       {  
         ErrProvider.SetError(cmb, "");  
       }  
       else  
       {  
         ErrProvider.SetError(cmb, message);  
       }  
       object[] control = ErrProvider.GetControls(tp).ToArray();  
       if (control.Length > 0)  
         return false;  
       else  
         return true;  
     }