ASP.Net Microsoft

Datetime format / Globalization

<pre class="default prettyprint prettyprinted"><code><span class="tag"><configuration>
</span><span class="tag"><system.web>
</span><span class="tag"><globalization</span><span class="atn">culture</span><span class="pun">=</span><span class="atv">"en-GB"</span><span class="tag">/>
</span><span class="tag"></system.web>
</span><span class="tag"></configuration></span></code></pre>
Tips & tricks

Gmail and Outlook

Login to your google account then access:

https://www.google.com/settings/security/lesssecureapps

Now you can configure your mail client with your gmail account.

Follow these steps:

http://www.configuraroutlook.com

 

 

Code Snippets

CKEditor

CKEditor is a ready-for-use HTML text editor designed to simplify web content creation. It’s a WYSIWYG editor that brings common word processor features directly to your web pages. Enhance your website experience with our community maintained editor

http://ckeditor.com

Tips & tricks

The Domain Name Expiration Process

This article focuses on the pre-release expiration process, which is now used for the majority of expired domain names.

read more »

Android

Make a hyperlink textview in android

TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));
Utils

JagPDF

JagPDF is a free, open source library for generating PDF documents.

The goal of this project is to provide a fast and reliable library that is usable in both server and desktop environments. The library is written in C++ and provides bindings for other languages. It runs on x86/Linux, amd64/Linux and x86/Windows platforms.

JagPDF aims to be easy to use, have a look at Hello World examples in C++, Python, Java or C. The library implements a fairly large subset of the PDF specification which enables creation of a broad range of document types.

The library is distributed under the MIT license which encourages both commercial and non-commercial usage. Consider contributing to JagPDF to keep it evolving and free.

http://www.jagpdf.org/

ArcGIS Javascript

Restrict pan and zoom in ArcGIS Javascript API


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Simple Map</title>
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/esri/css/esri.css">
<style>
html, body, #map {
height:100%;
width:100%;
margin:0;
padding:0;
}
body {
background-color:#FFF;
overflow:hidden;
font-family:"Trebuchet MS";
}
</style>
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/"></script>
<script>
dojo.require("esri.map");
var map = null;
var extent =  null;
var maxExtent = null;

function init() {
map = new esri.Map("map",{
basemap:"topo",
center:[-122.45,37.75], //long, lat
zoom:13,
sliderStyle:"small"
});
//set max extent to inital extent
dojo.connect(map, "onLoad", function(){
maxExtent = map.extent;
});

//check to see if map is within max extent when its extent changes.  If not, roll back to the max
//extent that we set above
dojo.connect(map, "onExtentChange", function(extent){
if((map.extent.xmin < maxExtent.xmin) ||
(map.extent.ymin < maxExtent.ymin)  ||
(map.extent.xmax > maxExtent.xmax) ||
(map.extent.ymax > maxExtent.ymax)
) {
map.setExtent(maxExtent);
console.log("max extent reached, rolling back to previous extent");
}

});

}

dojo.ready(init);

</script>
</head>

<body class="claro">
<div id="map"></div>
</body>
</html>

http://jsfiddle.net/gh/gist/library/pure/6050806/

Tips & tricks

How to configure Microsoft.AspNet.FriendlyUrls

App_code>start>RouteConfig.vb

Imports Microsoft.VisualBasic
Imports System.Web.Routing
Imports Microsoft.AspNet.FriendlyUrls

Public Class RouteConfig
    Public Shared Sub RegisterRoutes(routes As RouteCollection)
        Dim settings = New FriendlyUrlSettings()
        settings.AutoRedirectMode = RedirectMode.Permanent
        routes.EnableFriendlyUrls(settings)
    End Sub
End Class

Global.asax

<%@ Import Namespace="System.Web.Routing" %>
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    'Friendly URLs
    RouteConfig.RegisterRoutes(RouteTable.Routes)
End Sub

Generate Friendly URLs without string concatenation


<a href="<%: FriendlyUrl.Href("~/Foo", "bar", 34) %>">Click me</a>

if error on server:

Could not load file or assembly 'Microsoft.Web.Infrastructure,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
 or one of its dependencies. The system cannot find the file specified

Run ASP.NET MVC 3 Tools Update
http://www.microsoft.com/en-us/download/confirmation.aspx?id=1491

related links:
http://www.hanselman.com/blog/CommentView.aspx?guid=724141DA-9E27-44AE-A370-9E311BAED472#73cdc003-407d-4d9a-8ea0-d397b5989cf4

http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx

Code Snippets .NET ASP.Net regex

ASP.Net Character Length Regular Expression Validators

ASP.Net RegularExpression Validators

Maximum character length Validation (Maximum 6 characters allowed)

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1"
Display = "Dynamic"
ControlToValidate = "TextBox1"
ValidationExpression = "^[\s\S]{0,6}$"
ErrorMessage="Maximum 6 characters allowed.">
</asp:RegularExpressionValidator>

Minimum character length Validation (Minimum 6 characters required)

<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator2"
Display = "Dynamic"
ControlToValidate = "TextBox2"
ValidationExpression = "^[\s\S]{6,}$"
ErrorMessage="Minimum 6 characters required.">
</asp:RegularExpressionValidator>

Minimum and Maximum character length Validation (Minimum 2 and Maximum 6 characters required)

<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator3"
Display = "Dynamic"
ControlToValidate = "TextBox3"
ValidationExpression = "^[\s\S]{2,6}$"
ErrorMessage="Minimum 2 and Maximum 6 characters required.">
</asp:RegularExpressionValidator>

Alphanumeric with special Characters
Minimum length 7 and Maximum length 10. Characters allowed – a – z A – Z 0-9 ’@ & # .

<asp:RegularExpressionValidator ID="RegExp1" runat="server"
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate=" txtPassword "
ValidationExpression="^[a-zA-Z0-9'@&#.\s]{7,10}$" />

Alphanumeric Only
Minimum length 7 and Maximum length 10. Characters allowed – a – z A – Z 0-9

<asp:RegularExpressionValidator ID="RegExp1" runat="server"
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate=" txtPassword "
ValidationExpression="^[a-zA-Z0-9\s]{7,10}$" />

Alphabets Only
Minimum length 7 and Maximum length 10. Characters allowed – a – z A – Z

<asp:RegularExpressionValidator ID="RegExp1" runat="server"
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate="txtPassword"
ValidationExpression="^[a-zA-Z]{7,10}$" />

Numeric Only
Minimum length 7 and Maximum length 10. Characters allowed – 0 – 9

<asp:RegularExpressionValidator ID="RegExp1" runat="server"
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate="txtPassword"
ValidationExpression="^[0-9]{7,10}$" />

source:
http://www.aspsnippets.com/Articles/ASP.Net-Regular-Expression-Validator-to-validate-Minimum-and-Maximum-Text-Length.aspx

VBA

VBA environment variables (ENVIRON)

To see a list of variables, create a sub:

 
Sub ListEnvironmentVariables()

    'each environment variable in turn
    Dim EnvironmentVariable As String
    
    'the number of each environment variable
    Dim EnvironmentVariableIndex As Integer
    
    'get first environment variables
    EnvironmentVariableIndex = 1
    EnvironmentVariable = Environ(EnvironmentVariableIndex)
    
    'loop over all environment variables till there are no more
    Do Until EnvironmentVariable = ""
    
    'get next e.v. and print out its value
    Debug.Print EnvironmentVariableIndex, EnvironmentVariable
    
    'go on to next one
    EnvironmentVariableIndex = EnvironmentVariableIndex + 1
    EnvironmentVariable = Environ(EnvironmentVariableIndex)
    
    Loop

End Sub
 

click menu “View” > “Immediate Window” and run it
Doesn’t work on macintosh

Private Sub Workbook_Open()
'Generates a GUID:
Sheet1.Cells(8, 3).Value = Mid$(CreateObject("Scriptlet.TypeLib").GUID, 2, 36)  

'environment variables:
Sheet1.Cells(11, 3).Value = Environ$("computername")  
Sheet1.Cells(12, 3).Value = Environ$("username")
Sheet1.Cells(13, 3).Value = Environ$("USERPROFILE")
 
MsgBox "Hello " & Environ$("username")

End Sub

on Macintosh Excel you can try a AppleScript, something like:

Function GetUserNameMac() As String
    Dim sMyScript As String

    sMyScript = "set userName to short user name of (system info)" & vbNewLine & "return userName"

    GetUserNameMac = MacScript(sMyScript)
End Function