rss
twitter
facebook

Home

Mostrar mensagens com a etiqueta C#. Mostrar todas as mensagens
Mostrar mensagens com a etiqueta C#. Mostrar todas as mensagens

How to clear Query string value in asp.net

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("id");
 
http://www.codeproject.com/Questions/310625/How-to-clear-Query-string-value-in-net 

Read More

how to format datetime in gridview for minutes OR Date



FORMAT MINUTES
<asp:BoundField DataField="HoraAT" HeaderText="Hora" ReadOnly="True" SortExpression="HoraAT" DataFormatString="{0:hh}:{0:mm}" />


FORMAT DATE

<asp:BoundField DataField="CriatedOn" HeaderText="CriatedOn"  DataFormatString="{0:yyyy-MM-dd}"      SortExpression="CriatedOn" Visible="false"/>
Read More

Field GridView with Link with Parameter

<asp:HyperLinkField Text="&lt;img src='../Img/view.png' alt='alternate text' border='0'/&gt;"
                    DataNavigateUrlFields="Id"  DataNavigateUrlFormatString="PAGE.aspx?Id={0}"
                    HeaderImageUrl="../Img/view.png" >
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:HyperLinkField>
Read More

Object Data Source Select Parameter

<SelectParameters>
 <asp:ControlParameter ControlID="field" DbType="String" DefaultValue="1" Direction="Input" Name="ParameterName"  PropertyName="Text" />
</SelectParameters>
Read More

DataGridView COL with Image

<asp:TemplateField>
 <ItemTemplate>
  <asp:Image ID="Image1" Height="32px" runat="server" ImageUrl='<%# String.Format("{0}{1}{2}", "PATH", Eval("FIELD"),".jpg") %>' />
 </ItemTemplate>
 <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
Read More

Convert short


Convert.ToInt16(field)


Read More

How to view Server Variables

foreach (string x in Request.ServerVariables)
{
Response.Write(x +
": " + Request.ServerVariables[x] + "<br>");
}
Read More

NTLM - ASPX C#


Properties project

Servers

click checkbox -> NTLM authentication

web.config

<authentication mode="Windows">
</
authentication>

IIS

Authentication -> windows authentication -> Enable
Authentication -> windows authentication -> Providers -> put NTLM first 
Read More

FeedbackMessage

.ASPX AFTER
<%= this.message %>
.CSS --------------------------------------------------------------------------------- .errorBox { border:solid 2px Red; padding: 3px 3px 3px 3px; color:Red; text-align:left; } .errorImage { vertical-align:bottom; margin-bottom:-5px; } .InfoBox { border:solid 1px Blue; padding: 3px 3px 3px 3px; font-size:11px; } .InfoImage { vertical-align:bottom; margin-top:-6px; } .msbox { position: fixed; width: 400px; float:left; z-index: 8000; top: -50px; left:40%; } .msboximg { position: absolute; float: right; right: -10px; top: -10px; } .messagebox { background-color: Blue; height: 40px; text-align: center; width: 100%; } .MessageText { vertical-align: middle; margin-top: 5px; font-family: Trebuchet MS; color: White; } .userbox { background-color: #90D0f0; } .contentbox { background-color: #F5F9FF; } --------------------------------------------------------------------------------- .CS public enum MessageType{SUCCESS,WARNING,INFO,FAIL}; public void ShowMessage(string message,MessageType Type = MessageType.INFO,string MoreInfo="") { this.message = message; this.msmtext.Attributes["Title"] = MoreInfo; switch(Type) { case MessageType.FAIL: this.Messagebox.Style["background-color"] = "Red"; break; case MessageType.INFO: this.Messagebox.Style["background-color"] = "Blue"; break; case MessageType.SUCCESS: this.Messagebox.Style["background-color"] = "Green"; break; case MessageType.WARNING: this.Messagebox.Style["background-color"] = "Orange"; break; } }
Read More

How to replace single quotes

How to solution replace " for ' it's simple you can use ASCII table chr(34)


To solve such problems, use the command like this

replace(,chr(34),”'“)
Read More

Get Years From 1980

Send the RecordList Years below1980

public void MssGetYears(out RLYearsRecordList ssOutput) {
            ssOutput = new RLYearsRecordList(null);
            int currentYear = DateTime.Now.Year;

            for (int i = currentYear; i >= 1980; i--)
            {
                RCYearsRecord rcYear = new RCYearsRecord();
                rcYear.ssSTYears.ssYear = i.ToString();
                ssOutput.Append(rcYear);
            }
            // TODO: Write implementation for action
        }

Code By http://informatictips.blogspot.com/
Read More

Radom Colours

        public void MssRandomColour(out string ssColour)
        {
            ssColour = string.Empty;
            Random random = new Random();
            System.Threading.Thread.Sleep(250);
            char[] valid = { 'A', 'B', 'C', 'D', 'E', 'F', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
            StringBuilder sb = new StringBuilder("");
            for(int i = 0; i < 6; i++)
            {
                sb.Append(valid[random.Next(valid.Length)]);
            }
            ssColour = "#" + sb.ToString();       

            // TODO: Write implementation for action
        }
Read More

ConvertToKbAndMb

public void MssConvertToKbAndMb(string ssbytes, out string ssKb, out string ssMb)
{
            ssKb = string.Empty;
            ssMb = string.Empty;

            // Convert bytes to megabytes.
            double megabytes1 = ConvertBytesToMegabytes(double.Parse(ssbytes));

            ssMb = Math.Round(megabytes1, 2).ToString() + " Mb";

            // Convert bytes to kilobytes.
            double kilobytes = ConvertBytesToKilobytes(double.Parse(ssbytes));

            // Write the result.
            ssKb = Math.Round(kilobytes).ToString() + " Kb";


            // TODO: Write implementation for action
        } // MssConvertToKbAndMb


        static double ConvertBytesToMegabytes(double bytes)
        {
            return (bytes / 1024f) / 1024f;
        }

        static double ConvertBytesToKilobytes(double bytes)
        {
            return bytes / 1024f;
        }
Read More

How To Change a User Password with C# and Active Directory

using System;
using System.DirectoryServices;

class Testclass
{
       
static void Main()
       
{
               
string userName = "Bob";
               
string oldPassword = "123shoot"
               
string newPassword = "KJ#$#H";

               
Console.WriteLine("changing password for " + userName + " from "  
                                       
+ oldPassword + " to " + newPassword);

               
ChangePassword(userName, oldPassword, newPassword);

       
}

       
public static void ChangePassword(string userName, string oldPassword, string newPassword)
       
{
               
string path = "LDAP://CN=" + userName + ",CN=Users,DC=demo,DC=domain,DC=com";

               
//Instantiate a new DirectoryEntry using an administrator uid/pwd
               
//In real life, you'd store the admin uid/pwd  elsewhere
               
DirectoryEntry directoryEntry = new DirectoryEntry(path, "administrator", "password");

               
try
               
{
                   directoryEntry
.Invoke("ChangePassword", new object[]{oldPassword, newPassword});
               
}
               
catch (Exception ex)  //TODO: catch a specific exception ! :)
               
{
                   
Console.WriteLine(ex.Message);
               
}

               
Console.WriteLine("success");
       
}
}


http://www.rootsilver.com/2007/08/how-to-change-a-user-password.html
Read More

Rating

 
<asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="True">
            <ContentTemplate>
                <ul>
                    <li>An example of five-star rating:
                        <br />
                       
                        <ajaxToolkit:rating runat="server" ID="Rating1"
                            MaxRating="5"
                            CurrentRating="2"
                            CssClass="ratingStar"
                            StarCssClass="ratingItem"
                            WaitingStarCssClass="Saved"
                            FilledStarCssClass="Filled"
                            EmptyStarCssClass="Empty" AutoPostBack="True" OnChanged="Rating1_Changed"
                            >
                        </ajaxToolkit:rating>
                        <asp:Label ID="labelCaption1" runat="server" Text="Selected value: " />
                        <asp:Label ID="labelValue1" runat="server" Text=""></asp:Label>
                    </li>
                   </ul>
            </ContentTemplate>
        </asp:UpdatePanel>


 DOWNLOAD

 
AjaxRatingCS.rar
Read More

Connection Strings

This code below has to be placed in the Web.config file






for more connections Strings go to http://www.connectionstrings.com/
Read More

Calculator

using System.Collections.Generic;
using System.Text;

namespace Calculadora
{
    class Program
    {
        static void Main(string[] args)
        {
            // Declaração de variáveis
            ConsoleKeyInfo n1, n2, op;
            string operacao;


            int resultado = 0;

            Console.Write("SEJA BEM VINDO AO 1º PROGRAMA EM C# DE ALGORITMOS");

            // Recolher 1º oprerando
            Console.Write("\nIntroduza o primeiro operando: ");
            n1 = Console.ReadKey(true);
            Console.Write("\n1º operando: " + (n1.KeyChar));

            // Recolher operação
            Console.Write("\n\nIntroduza a operação: ");
            op = Console.ReadKey(true);
            Console.Write("\nOperação: " + (op.KeyChar));

            // Verificação da necessidade de 2º operando
            operacao = Convert.ToString(op.KeyChar);
            //if (object.Equals(operacao, "+") || object.Equals(operacao, "-") || object.Equals(operacao, "*") || object.Equals(operacao, "/"))
            if (operacao.Equals("+") || operacao.Equals("-") || operacao.Equals("*") || operacao.Equals("/"))
            {
                // Recolher 2º oprerando
                Console.Write("\n\nIntroduza o segundo operando: ");
                n2 = Console.ReadKey(true);
                Console.Write("\n2º operando: " + n2.KeyChar);

                // Efectuar operação
                if (object.Equals(operacao, "+")) resultado = (n1.KeyChar - 48) + (n2.KeyChar - 48);
                else
                    if (object.Equals(operacao, "-")) resultado = (n1.KeyChar - 48) - (n2.KeyChar - 48);
                    else
                        if (object.Equals(operacao, "*")) resultado = (n1.KeyChar - 48) * (n2.KeyChar - 48);
                        else
                            if (object.Equals(operacao, "/") && n2.KeyChar - 48 != 0)
                            {
                                resultado = (n1.KeyChar - 48) / (n2.KeyChar - 48);
                            }
                            else
                            {
                                Console.Write("\n\n### ERRO ###\nImpossível dividir por 0.");
                            }

                // Mostrar resultado
                Console.Write("\n\nO resultado de " + n1.KeyChar + op.KeyChar + n2.KeyChar + " é " + resultado + ".");
            }
            else
            {
                Console.Write("\n\nNÃO HÁ OPERAÇÕES COM APENAS 1 OPERADOR NA VERSÃO 0.1!");
            }
           
            Console.Read();
        }
    }
}

Read More

Samples for everyone about developing on C#

sample :


public static bool IsLocalIpAddress(string host)
{
try
{ // get host IP addresses
IPAddress[] hostIPs = Dns.GetHostAddresses(host);
// get local IP addresses
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());

// test if any host IP equals to any local IP or to localhost
foreach (IPAddress hostIP in hostIPs)
{
// is localhost
if (IPAddress.IsLoopback(hostIP)) return true;
// is local address
foreach (IPAddress localIP in localIPs)
{
if (hostIP.Equals(localIP)) return true;
}
}
}
catch { }
return false;
}


You can test the method for example like this:
[C#]

IsLocalIpAddress("localhost"); // true (loopback name)
IsLocalIpAddress("127.0.0.1"); // true (loopback IP)
IsLocalIpAddress("MyNotebook"); // true (my computer name)
IsLocalIpAddress("192.168.0.1"); // true (my IP)
IsLocalIpAddress("NonExistingName"); // false (non existing computer name)
IsLocalIpAddress("99.0.0.1"); // false (non existing IP in my net)



Code by : http://www.csharp-examples.net/examples/
Read More
 
Powered by Blogger