Source Code examples

Last post 06-27-2009 12:36 PM by SGWellens. 24 replies.

Sort Posts:

  • Source Code examples

    06-18-2009, 4:58 PM
    • All-Star
      41,831 point All-Star
    • tmorton
    • Member since 08-06-2002, 9:37 PM
    • SE Pennsylvania, USA
    • Posts 6,968
    • ASPInsiders
      Moderator

    Here is some code.

    C#

     

    1    using System.Web;
    2 using System.Web.Routing;
    3
    4 namespace MvcApplication1.Constraints
    5 {
    6 public class LocalhostConstraint : IRouteConstraint
    7 {
    8 public bool Match
    9 (
    10 HttpContextBase httpContext,
    11 Route route,
    12 string parameterName,
    13 RouteValueDictionary values,
    14 RouteDirection routeDirection
    15 )
    16 {
    17 return httpContext.Request.IsLocal;
    18 }
    19
    20 }
    21 }

     

    VB

    1    Public Class LocalhostConstraint
    2 Implements IRouteConstraint
    3
    4 Public Function Match( _
    5 ByVal httpContext As HttpContextBase, _
    6 ByVal route As Route, _
    7 ByVal parameterName As String, _
    8 ByVal values As RouteValueDictionary, _
    9 ByVal routeDirection As RouteDirection _
    10 ) As Boolean Implements IRouteConstraint.Match
    11
    12 Return httpContext.Request.IsLocal
    13 End Function
    14
    15 End Class

     

    SQL

    1    SELECT TOP 1000 [EventLogID]
    2 ,[Message]
    3 ,[Category]
    4 ,[SettingsID]
    5 ,[EventID]
    6 ,[EventType]
    7 ,[EventDate]
    8 ,[MachineName]
    9 FROM [somedb].[dbo].[sometable] WHERE SettingsID = 1000 AND Message LIKE 'Top%' ORDER BY 1 desc

     

    C# with comments and slashes

    1    var targetSchemeAndHost = "http://" + targetHost;
    2 //comment;

     

    VB with comments and single quote

     

    1    Dim s As String = "A string with ' a single quote"
    2 'comment

     

    longer C#

    1    public bool public class Collection:CollectionBase
    2
    3 {
    4
    5 public Collection()
    6
    7 {
    8
    9 //
    10
    11 // TODO: Add constructor logic here
    12
    13 //

    14
    15 }
    16
    17 public T this[int index]
    18
    19 {
    20
    21 get { return (T)this.List[index]; }
    22
    23 set { this.List[index] = value; }
    24
    25 }
    26
    27
    28
    29 public int IndexOf(T item)
    30
    31 {
    32
    33 return this.List.IndexOf(item);
    34
    35 }
    36
    37
    38
    39 public int Add(T item)
    40
    41 {
    42
    43 return this.List.Add(item);
    44
    45 }
    46
    47
    48
    49 public void Remove(T item)
    50
    51 {
    52
    53 this.List.Remove(item);
    54
    55 }
    56
    57
    58
    59 public void CopyTo(Array array, int index)
    60
    61 {
    62
    63 this.List.CopyTo(array, index);
    64
    65 }
    66
    67
    68
    69 public void AddRange(Collection collection)
    70
    71 {
    72
    73 for (int i = 0; i < collection.Count; i++)
    74
    75 {
    76
    77 this.List.Add(collection[i]);
    78
    79 }
    80
    81 }
    82
    83 public void AddRange(T[] collection)
    84
    85 {
    86
    87 this.AddRange(collection);
    88
    89 }
    90
    91 Contains(T item)
    92
    93 {
    94
    95 return this.List.Contains(item);
    96
    97 }
    98
    99 public void Insert(int index, T item)
    100
    101 {
    102
    103 this.List.Insert(index, item);
    104
    105 }
    106
    107 }

     

    C# generics

    1    Stack<int> intStack = new Stack<int>();
    2
    3 Dictionary<string, string> dictionary = new Dictionary<string, string>();
    4
    5 public void MyGenericMethod(T x, T y)
    6
    7 {
    8
    9 Console.Writeline("Parameters type is {0}", typeof(T));
    10
    11 }

     

    pound sign (#) in href attribute

     

    1    <a href="http://forums.asp.net/EditPost.aspx?PostID=3243610&ReturnUrl=%2fthemes%2ffan%2fforums%2fthread.aspx%3fThreadID%3d1437326%26PostID%3d3243610%26PermaPostID%3d3243610%233243610#" mce_href="http://forums.asp.net/EditPost.aspx?PostID=3243610&ReturnUrl=%2fthemes%2ffan%2fforums%2fthread.aspx%3fThreadID%3d1437326%26PostID%3d3243610%26PermaPostID%3d3243610%233243610#">Test</a>
      

     

    expressions + ) turning into BLOCKED EXPRESSION

    CTE (common table expressions)

     

    Pasting from Word

     

    Please my dear Aunt Sally

     
    Terri Morton
    ASP.NET Website Manager, Neudesic
  • Re: Source Code examples

    06-18-2009, 9:43 PM
    • All-Star
      90,561 point All-Star
    • SGWellens
    • Member since 01-02-2007, 9:27 PM
    • Twin Cities, MN
    • Posts 7,389
    • Moderator
      TrustedFriends-MVPs

    Here is some more code.....DOH!

     

        protected void Button1_Click(object sender, EventArgs e)
        {
            // code with html markup in a string
            String Test = "&lt;bold>Hello Pandora!</bold>";
    
            Response.Write(Test);
        }
    

     

    Steve Wellens

    My blog
  • Re: Source Code examples

    06-23-2009, 10:30 PM
    • All-Star
      41,831 point All-Star
    • tmorton
    • Member since 08-06-2002, 9:37 PM
    • SE Pennsylvania, USA
    • Posts 6,968
    • ASPInsiders
      Moderator

    C# with comments and slashes

    var targetSchemeAndHost = "http://" + targetHost;
    //comment;
    


     

    VB with comments and single quote

    Dim s As String = "A string with ' a single quote"
    'comment
    


    C# generics

    Stack<int> intStack = new Stack<int>();
    
    Dictionary<string, string> dictionary = new Dictionary<string, string>();
    
    public void MyGenericMethod(T x, T y)
    
    {
    Console.Writeline("Parameters type is {0}", typeof(T));
    }


    pound sign (#) in href attribute

    <a href="#">test</a>

     

    expressions + ) turning into BLOCKED EXPRESSION

    CTE (common table expressions)

     

    pasting from Word

    Please my dear Aunt Sally

    Terri Morton
    ASP.NET Website Manager, Neudesic
  • Re: Source Code examples

    06-23-2009, 10:32 PM
    • All-Star
      41,831 point All-Star
    • tmorton
    • Member since 08-06-2002, 9:37 PM
    • SE Pennsylvania, USA
    • Posts 6,968
    • ASPInsiders
      Moderator

    Please my dear Aunt Sally

    Terri Morton
    ASP.NET Website Manager, Neudesic
  • Re: Source Code examples

    06-23-2009, 10:33 PM
    • All-Star
      41,831 point All-Star
    • tmorton
    • Member since 08-06-2002, 9:37 PM
    • SE Pennsylvania, USA
    • Posts 6,968
    • ASPInsiders
      Moderator

    Steve's code

        protected void Button1_Click(object sender, EventArgs e)
        {
            // code with html markup in a string
            String Test = "<bold>Hello Pandora!</bold>";
    
            Response.Write(Test);
        }
     



    Terri Morton
    ASP.NET Website Manager, Neudesic
  • Re: Source Code examples

    06-23-2009, 10:54 PM
    • All-Star
      97,915 point All-Star
    • mbanavige
    • Member since 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 10,343
    • Moderator
      TrustedFriends-MVPs

    markup:

        <asp:ListView ID="ListView1" runat="server">
            <LayoutTemplate>
                <div>
                    <asp:PlaceHolder runat="server" ID="ItemPlaceholder" />
                </div>
            </LayoutTemplate>
            <ItemTemplate>
                <div>
                    <%#Eval("ID")%>
                    :
                    <asp:Label ID="someDate" runat="server" Text='<%#Eval("someDate", "{0:yyyy}")%>' />
                </div>
            </ItemTemplate>
        </asp:ListView>




     


     

    Mike Banavige
    ~~~~~~~~~~~~
    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
  • Re: Source Code examples

    06-23-2009, 11:00 PM
    • All-Star
      97,915 point All-Star
    • mbanavige
    • Member since 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 10,343
    • Moderator
      TrustedFriends-MVPs

    didnt use insert code:

    <asp:ListView ID="ListView1" runat="server">
            <LayoutTemplate>
                <div>
                    <asp:PlaceHolder runat="server" ID="ItemPlaceholder" />
                </div>
            </LayoutTemplate>
            <ItemTemplate>
                <div>
                    <%#Eval("ID")%>
                    :
                    <asp:Label ID="someDate" runat="server" Text='<%#Eval("someDate", "{0:yyyy}")%>' />
                </div>
            </ItemTemplate>
        </asp:ListView>
     

    Mike Banavige
    ~~~~~~~~~~~~
    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
  • Re: Source Code examples

    06-23-2009, 11:02 PM
    • All-Star
      97,915 point All-Star
    • mbanavige
    • Member since 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 10,343
    • Moderator
      TrustedFriends-MVPs

    Small bit of text that I will copy/paste from Word

    Mike Banavige
    ~~~~~~~~~~~~
    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
  • Re: Source Code examples

    06-23-2009, 11:08 PM
    • All-Star
      90,561 point All-Star
    • SGWellens
    • Member since 01-02-2007, 9:27 PM
    • Twin Cities, MN
    • Posts 7,389
    • Moderator
      TrustedFriends-MVPs

    XML:

    <?xml version="1.0" standalone="yes"?>
    <Golfers>
      <Golfer ID="1" Name="Bobby Jones" Birthday="1902-03-17T00:00:00-05:00" />
      <Golfer ID="2" Name="Sam Snead" Birthday="1912-05-27T00:00:00-05:00" />
      <Golfer ID="3" Name="Tiger Woods" Birthday="1975-12-30T00:00:00-06:00" />
    </Golfers>



     

    Word:

    A red fox jumped over a lazy blue dog...should have colored text.

     

    Hmmm...Apparently message preview isn't operational yet.

     

    Pre

    Steve Wellens

    My blog
  • Re: Source Code examples

    06-23-2009, 11:15 PM
    • All-Star
      41,831 point All-Star
    • tmorton
    • Member since 08-06-2002, 9:37 PM
    • SE Pennsylvania, USA
    • Posts 6,968
    • ASPInsiders
      Moderator

    SGWellens:
    Hmmm...Apparently message preview isn't operational yet.
     

    Which browser?  It's working OK for me in IE8.

    Terri Morton
    ASP.NET Website Manager, Neudesic
  • Re: Source Code examples

    06-23-2009, 11:32 PM
    • All-Star
      97,915 point All-Star
    • mbanavige
    • Member since 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 10,343
    • Moderator
      TrustedFriends-MVPs

    I get previews too, but the code treatment doesn't kick in when previewing.

    ps: bonjour from safari 4 (hack free)

    Mike Banavige
    ~~~~~~~~~~~~
    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
  • Re: Source Code examples

    06-24-2009, 12:33 AM
    • All-Star
      41,831 point All-Star
    • tmorton
    • Member since 08-06-2002, 9:37 PM
    • SE Pennsylvania, USA
    • Posts 6,968
    • ASPInsiders
      Moderator

    regex (regular expression)

    Terri Morton
    ASP.NET Website Manager, Neudesic
  • Re: Source Code examples

    06-24-2009, 1:28 AM
    • All-Star
      62,769 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 1:34 PM
    • England
    • Posts 12,247
    • TrustedFriends-MVPs

    Code paste now works

        #region " Calc Functions           "
        /// <summary>
        /// Calculate Percentage from Decimal Values
        /// </summary>
        /// <param name="decExpression1">Numerator value</param>
        /// <param name="decExpression2">Divisor value</param>
        /// <returns>Calculated percentage</returns>
        public static decimal CalcPercent(decimal decExpression1, decimal decExpression2)
        {
          if (decExpression2 == 0)
          {
            return 0;
          }
          return 100 * (decExpression1 / decExpression2);
        }

        /// <summary>
        /// Calculate Percentage from Integer Values
        /// </summary>
        /// <param name="expression1">Numerator value</param>
        /// <param name="expression2">Divisor value</param>
        /// <returns>Calculated Percentage</returns>
        public static int CalcPercent(int expression1, int expression2)
        {
          if (expression2 == 0)
          {
            return 0;
          }
          return (int)(100 * (long)expression1) / expression2;
        }
        #endregion

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Source Code examples

    06-24-2009, 2:59 AM
    • All-Star
      123,169 point All-Star
    • XIII
    • Member since 06-30-2002, 11:59 PM
    • Essen, Belgium
    • Posts 13,627
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs
    body
    {
    	margin: 0;
    	padding: 0;
    	font-family: Arial,Helvetica,sans-serif;
    	font-size: .88em;
    	color: #4c4c4c;
    	cursor: default;
    }
    html *
    {
    	margin: 0;
    	padding: 0;
    }


    Css test.

    Grz, Kris. 

  • Re: Source Code examples

    06-24-2009, 3:15 AM
    • All-Star
      123,169 point All-Star
    • XIII
    • Member since 06-30-2002, 11:59 PM
    • Essen, Belgium
    • Posts 13,627
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs
    body
    {
    	margin: 0;
    	padding: 0;
    	font-family: Arial,Helvetica,sans-serif;
    	font-size: .88em;
    	color: #4c4c4c;
    	cursor: default;
    }
    html *
    {
    	margin: 0;
    	padding: 0;
    }

    How to get the fancy borders? Which options do you choose? And shouldn't these be best be standardized? I would also propose to use the 2.0 version of syntaxhighlighter. Looks prettier.

    Grz, Kris.
     

Page 1 of 2 (25 items) 1 2 Next >
Microsoft Communities