Posts

Showing posts from December, 2012

You work in a company, and need to send an email to a user, and a copy of that email to your manager. Which code should you use?

A.  MailMessage msg = new MailMessage();
msg.From = "from@yourcompany.com";
msg.To = "to@to.com, manager@yourcompany.com";
msg.Subject = "...";
msg.Body = "...";
SmtpClient client = new SmtpClient();
client.Send(msg);
B.  MailMessage msg = new MailMessage("from@yourcompany.com", "to@to.com");
msg.CC.Add(new MailAddress("manager@yourcompany.com"));
msg.Subject = "...";
msg.Body = "...";
SmtpClient client = new SmtpClient();
client.Send(msg);
C.  MailMessage msg = new MailMessage("from@yourcompany.com", "to@to.com");
msg.CC.Add(new MailAddress("manager@yourcompany.com"));
msg.Subject = "...";
msg.Body = "...";
SmtpClient client = new SmtpClient();
msg.Send(client);
D.  MailMessage msg = new MailMessage();
msg.From = "from@yourcompany.com";
msg.To = "to@to.com, manager@yourcompany.com";
msg.Subject = "...";
msg.Body = ".…

You are developing a .NET assembly which will be used from both, .NET components and COM components. Which 3 utilities do you need to use to ensure that COM components can access your assembly as easily as possible?

·Signtool ·Gacutil ·Sn ·Tlbimp ·regasm

What are the restrictions imposed on the signature of a method that is called when a serialization event occurs?

A.  Must not have any parameters (void) B.  Must not return anything (void) C.  Must take a StreamingContext parameter D.  Must return a StreamingContext object

split a string with multiple separators in javascript?

multibox text area values
var urlsArr = textarea.value.replace(/\r\n/g, "\n").split(/[\n,]+/);

Memory Cleaner that forces GC to collect objects in asp.net or Wcf or Window service

The following example demonstrates how to use the Collect method to perform a collection on all generations of memory. The code generates a number of unused objects, and then calls the Collect method to clean them from memory.

[DllImportAttribute("Kernel32.dll", EntryPoint = "SetProcessWorkingSetSize", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
    private static extern int ProcessWorkingSetSize(IntPtr Process, int minimumWorkingSetSize, int maximumWorkingSetSize);
    public void Flushmemory()
    {
        GC.Collect();
        GC.WaitForPendingFinalizers();
        if (Environment.OSVersion.Platform == PlatformID.Win32NT)
        {
            ProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
        }
    }

RowDataBound Event of GridView and take footer sum value in asp.net with C#

We are using RowDataBound event to perform summation in footer row.
we will show you how to display a summary or the sum of values in a particular column, in the GridView footer row. Also known as running total of a column, these accumulated figures needs to be displayed below all the pages, if GridView Paging is set as “True”.

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TotalsCnt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
                TotaloCnt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
                TotalcCnt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
                TotalSaCnt += Convert.ToInt32((DataBinder.Eval(e.Row.DataItem, "DataBaseValue")));
                TotalAmt += Convert.ToInt32((DataBinder.Eval…

Remove QueryString value using Asp.net

To clear all query strings, you can invoke the Request.QueryString.Clear();
which will remove all the querystrings at the url
To remove a specific querystring invoke Request.QueryString.Remove("name of the querystring").

Please follow below Example


PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
            // make collection editable
            isreadonly.SetValue(this.Request.QueryString, false, null);
            // remove
            this.Request.QueryString.Remove("op");

How to check a checkbox on gridview using javascript

<script type="text/javascript">
        function Delete(id) {    
            var frm = document.forms[0];
            for (i = 0; i < frm.elements.length; i++) {
                if (frm.elements[i].type == "checkbox") {
                    if (frm.elements[i].checked) {
                        if (confirm('Are you sure you want to delete the records?')) {
                            return true;
                        } else {
                            for (i = 0; i < frm.elements.length; i++) {
                                frm.elements[i].checked = false;
                            }
                            return false;
                        }
                    }
                }
            }
            alert("Please select a records to delete");
            return false;
        }
    </script>

 <asp:ImageButton ID="ImgBtnDelete" runat="server" ToolTip="Delete"
OnClientClic…

Reading Files in Asp.net or C# and Search for a particular text in files in a specific directory

using (StreamReader sr = new StreamReader("FilePath" + "Config.dat"))
{
    sConfigText = sr.ReadToEnd();
}
try
{
objEditvmta = new StringBuilder();
string Pickfile = "identifystring";
if (sConfigText.Contains(Pickfile))
{
   StartPoint = sConfigText.Substring(0, sConfigText.IndexOf(Pickfile)) + Environment.NewLine;
   RemainingText = sConfigText.Substring(StartPoint.Length - 1);
   EntairText = RemainingText.Substring(RemainingText.IndexOf("EndingstringValue") + "EndingstringValue Length");
   objVmta.Append(StartPoint.TrimEnd());
   objVmta.Append(EntairText.TrimEnd());
   sConfigEditData = objVmta.ToString();
   FinalDeletePattern = sConfigEditData;
   FileStream fsPattern = File.OpenWrite("FilePath" + "FileName");
   Encoding encPattern = Encoding.ASCII;
   byte[] restPattern = encPattern.GetBytes(sConfigEditData.ToString());
   fsPattern.Write(restPattern, 0, sConfigEditData.Length);
   fsPattern.Flush();
   fsPat…