CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching tags of .NET
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
 
namespace Westwind.Web.Services
{
    /// <summary>
    /// Implements the Gravatar API for retrieving a Gravatar image to display
by Rick Strahl   December 15, 2011 @ 4:08pm
Tags: Gravatar, C#, .NET
216 Views
2 comments
 
<script type="text/javascript">
 
    function CustomValidatorOmbudsmanNotifiedDate(s, args) {
        var dt = args.Value
 
        if (!dt && $("*[id$='OmbudsmanNotifiedFlag'] input:checked").val() == '1') {
            args.IsValid = false;
        }
        else {
            args.IsValid = true;
by Cat   December 12, 2011 @ 3:27pm
44 Views
no comments
 
Dim funcs = (From x In [Enum].GetValues(GetType(SummaryFunc)) _
Order By x _
Select New With {.ID = CInt(x), .Name =
[Enum].GetName(GetType(SummaryFunc), x)}).ToList
by Thom Lamb   October 02, 2011 @ 10:15am
Tags: vb, .net, Linq, enum
62 Views
no comments
 
Module Module1
    Public Enum PivotAction
        Sum = 1
        Min = 2
        Max = 3
        Count = 4
    End Enum
    Public Function Pivot(ByVal SourceTable As DataTable, _
                          ByVal PrimaryKeyColumn As String, _
                          ByVal PivotNameColumn As String, _
by aKocen   September 26, 2011 @ 7:57am
83 Views
1 comments
 
C#
public float Value
        {
            get
            {
                object o = ViewState["Value"];
                if (o == null)
                    return 0;
                return (float)o;
            }
            set
by Robert Friberg   September 20, 2011 @ 2:36am
47 Views
no comments
 
C#
//Stored Guid as a string
string strGuid = "5152A989-279F-4A81-AC68-4696966CD1E2"
//Creating a GUID obj based on that guid string
new Guid(strGuid);
by Egli   August 15, 2011 @ 6:12pm
Tags: .NET, Guid
74 Views
no comments
 
C#
//using System.Web.UI
//.aspx page must have a reference to jquery (for the example described bellow)
 
string someScript= " $(window).bind('load', CodeToExcecute());";
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "someScript", someScript, true);
by Egli   August 04, 2011 @ 1:40am
99 Views
no comments
 
C#
string strFormatedGuid = Guid.NewGuid().ToString("N"); //Where N is the format, can be any of the ones described below
 
/*
Format: N
Output 32 digits:
00000000000000000000000000000000
 
Format: D
Output 32 digits separated by hyphens:
00000000-0000-0000-0000-000000000000
by Egli   August 02, 2011 @ 8:14pm
70 Views
no comments
 
C#
//using System.Globalization;
CultureInfo culture = new CultureInfo("en-AU");
DateTime week_start = Convert.ToDateTime("27/07/2011", culture);
by Egli   August 01, 2011 @ 12:27am
95 Views
no comments
 
C#
//using System.Web; 
 
//to return "http://www.samplepage.com/Egli/index.aspx"
string url = HttpContext.Current.Request.Url.AbsoluteUri;
 
//to return "/Egli/index.aspx"
string path = HttpContext.Current.Request.Url.AbsolutePath;
 
//to return "www.samplepage.com"
string host = HttpContext.Current.Request.Url.Host;
by Egli   July 25, 2011 @ 9:18pm
124 Views
no comments
 
XML
<!--Place this under the <system.web> node-->
<httpRuntime executionTimeout="1200" maxRequestLength="30720" />
by Egli   July 25, 2011 @ 5:41pm
102 Views
no comments
 
C#
/*
Note to reader:
There are two server variables of interest; REMOTE_ADDR and HTTP_X_FORWARDED_FOR. As many visitors access the internet via a third party (ie their ISP), 
REMOTE_ADDR does not always contain their IP address... it contains their ISP's address. If this is the case, most browsers then store the users IP address in the
HTTP_X_FORWARDED_FOR variable. So, first, we check HTTP_X_FORWARDED_FOR, and then if that is empty, we try REMOTE_ADDR instead:
*/
 
string IP_Address =  HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if(String.IsNullOrEmpty(IP_Address))
{
by Egli   July 25, 2011 @ 5:30pm
82 Views
no comments
 
C#
// create date time 2008-03-09 16:05:07.123
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);
 
String.Format("{0:y yy yyy yyyy}", dt);  // "8 08 008 2008"   year
String.Format("{0:M MM MMM MMMM}", dt);  // "3 03 Mar March"  month
String.Format("{0:d dd ddd dddd}", dt);  // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}",     dt);  // "4 04 16 16"      hour 12/24
String.Format("{0:m mm}",          dt);  // "5 05"            minute
String.Format("{0:s ss}",          dt);  // "7 07"            second
String.Format("{0:f ff fff ffff}", dt);  // "1 12 123 1230"   sec.fraction
by Egli   July 24, 2011 @ 10:54pm
69 Views
no comments
 
C#
// Just two decimal places
String.Format("{0:0.00}", 123.4567);      // "123.46"
String.Format("{0:0.00}", 123.4);         // "123.40"
String.Format("{0:0.00}", 123.0);         // "123.00"
 
// Max. two decimal places
String.Format("{0:0.##}", 123.4567);      // "123.46"
String.Format("{0:0.##}", 123.4);         // "123.4"
String.Format("{0:0.##}", 123.0);         // "123"
by Egli   July 24, 2011 @ 10:51pm
71 Views
no comments
 
C#
//using System.Web.Security
FormsAuthentication.SignOut();
by Egli   July 19, 2011 @ 7:35pm
87 Views
no comments
 
<asp:ListView ID="ListView_Example" runat="server" >
    <LayoutTemplate>
        <ul>
           <asp:PlaceHolder ID="PlaceHolder_Example" runat="server" />
        </ul>
    </LayoutTemplate>
    <ItemTemplate>
        <li>
           <a href="<%=Eval("ExampleLink")%>"><%=Eval("ExampleName")%></a><%=Eval("ExampleSeparator")%>
        </li>
by Egli   July 19, 2011 @ 7:10pm
Tags: .NET, ListView
68 Views
no comments
 
C#
//using System.Web.Security
 
if (Membership.ValidateUser(username, password))
{
   //Log in user.
   FormsAuthentication.SetAuthCookie(username, true);
}
else
{
   //Handle user not exist code.
by Egli   July 19, 2011 @ 6:32pm
89 Views
no comments
 
C#
DropDownList.SelectedIndex = DropDownList.Items.IndexOf(DropDownList.Items.FindByValue("Value"));
by Egli   July 18, 2011 @ 4:28pm
77 Views
no comments
 
XML
<!-- place under the <system.web> node-->
<webServices>
    <wsdlHelpGenerator href="denied.aspx" />
    <protocols>
       <remove name="HttpGet" />
       <remove name="HttpPost" />
    </protocols>
</webServices>
by Egli   July 18, 2011 @ 12:56am
86 Views
no comments
 
C#
void Main()
{
    AutoMapper.Mapper.CreateMap<Contact, KeyValuePair<Guid, string>>()
        .ConstructUsing(x => new KeyValuePair<Guid, string>(x.Id, x.FullName));
 
    //var contacts = ContactRepository.GetAll(); // Returns IList<Contact>
    var contacts = new List<Contact> {
        new Contact { Id = Guid.NewGuid(), FullName = "Joe Bob" },
        new Contact { Id = Guid.NewGuid(), FullName = "Sally Jones" },
    };
by mellamokb   July 15, 2011 @ 2:54pm
198 Views
no comments
 
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate