theDeSilva.com Andrew de Silva

Disable selection on browser using Javascript

March 10th, 2010 · No Comments · Javascript

Here’s a quick way to disable selection on browsers using Javascript. Helpful if you don’t want somebody to select a bunch of text and copy and paste.

1
2
3
4
5
6
7
8
9
10
11
12
13
window.onload = function() {
	disableSelection(document.body)
}
 
function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE 
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox 
	target.style.MozUserSelect="none"
else //All other ie: Opera
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}
Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Reddit
  • Technorati
  • Facebook
  • Google Bookmarks
  • LinkedIn

→ No CommentsTags:··

Batch File to Copy Flex Release Build to Production Server

February 4th, 2010 · No Comments · Flex

Here’s something that I always do when writing any sort of Flex Application. I’ll write a batch file that would allow me to quickly double click it and copy all of the files on the bin-release folder to the production server. This normally save me a lot of time as I don’t have to manually look for the files and copy them to the server.

Here’s a quick way to create the batch file and edit it to do what you want to ,

  1. Open up Notepad in Windows. You can do this by navigating to Start > Programs > Accessories > Notepad, or simply by entering notepad under Start > Run.
  2. Save your file before you start writing any code
  3. Go to File > Save As.
  4. Click on the dropdown box “Save as type:” and select “All files” instead of Text (*.txt).
  5. Add .bat to the end of your file name before you save. For example copy.bat.
  6. Click on Save.

Now a little batch commands to delete the files that exist on the production server first before we copy the files from the bin-release folder to the production server followed by opening the page using the default browser.

1
2
3
4
5
6
REM Delete old production files
del \\production_server_name\production_folder\*.*
REM Copy over new production files
copy *.* \\production_server_name\production_folder\
REM Open the location of the file using default browser
start www.production_server.com

The batch file should be located in the same folder as the files that you want to copy

Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Reddit
  • Technorati
  • Facebook
  • Google Bookmarks
  • LinkedIn

→ No CommentsTags:

Using cmd.exe with VB.NET – Process.Start

January 27th, 2010 · No Comments · .NET

Here’s a quick function to show the use of System.Diagnostic.Process which will allow you to start another application using VB.NET. The example below is used to call svnadmin to create a new repository ( Subversion ) by grabbing the repository name. The function also checks to see whether the directory exist on the file system and if it doesn’t it will start the command prompt svnadmin to create the folder. However if the folder does exist it will nag at you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Sub createRepo(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim repoName As String = repoNameInput.Text
 
        Dim dirExist As Boolean = False
 
        If System.IO.Directory.Exists("C:\svn_repository\" & repoName) Then
            dirExist = True
            result.Text = "<font color=""red"">Repository Already Exist !</font>"
        End If
 
        If (repoName.Length <> 0 And dirExist = False) Then
            Dim myProcess As Process = Process.Start("cmd.exe", "/k svnadmin create C:\svn_repository\" & repoName)
 
            myProcess.WaitForExit(10000)
            ' if the process doesn't complete within
            ' 10 seconds, kill it
 
            If Not myProcess.HasExited Then
                myProcess.Kill()
            End If
 
            result.Text = "Respository Created: " _
                & myProcess.ExitTime & _
                Environment.NewLine & _
                "Exit Code (Troubleshooting Purpose): " & _
                myProcess.ExitCode
        End If
 
    End Sub

You will have to import the following library to have the Process.Start to work.

1
Imports System.Diagnostics
Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Reddit
  • Technorati
  • Facebook
  • Google Bookmarks
  • LinkedIn

→ No CommentsTags:····

VB.NET Database query return result as XML

January 25th, 2010 · No Comments · .NET

A simple VB.NET page that takes a ID variable and return the result as XML page.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
Imports System.IO
Imports System.Xml
Imports System.Data
Imports System.Data.SqlClient
 
Partial Class writeXML
    Inherits System.Web.UI.Page
 
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        GetXML(Request.QueryString("pid"))
    End Sub
 
    Public Function sqlConnect() As SqlConnection
        Dim oCn As SqlConnection = New SqlConnection("Data Source=xxxx\xxxx; Initial Catalog=tableName; User Id=dbUSERNAME; Password=dbPASSWORD")
        Return oCn
    End Function
 
    Private Function GetDataSet(ByVal strSQL As String) As DataSet
 
        '1. Create a connection
        Dim myConnection As SqlConnection = sqlConnect()
 
        '2. Create the command object, passing in the SQL string    
        Dim myCommand As New SqlCommand(strSQL, myConnection)
 
        myConnection.Open()
 
        '3. Create the DataAdapter
        Dim myDataAdapter As New SqlDataAdapter()
        myDataAdapter.SelectCommand = myCommand
 
 
        '4. Populate the DataSet and close the connection
        Dim myDataSet As New DataSet()
        myDataAdapter.Fill(myDataSet)
        myConnection.Close()
 
        'Return the DataSet
        Return myDataSet
 
    End Function
 
 
    Public Sub GetXML(ByVal id As String)
 
        Dim sqlCommand As String
 
        sqlCommand = "SELECT column1, column2  "
        sqlCommand &= "FROM tableName "
        sqlCommand &= "WHERE id = '" & id & "';  "
 
        Dim retrievedDataSet As New DataSet
        retrievedDataSet = GetDataSet(sqlCommand)
 
        Dim xmlDocument As XmlDocument = New XmlDocument
        xmlDocument.LoadXml(retrievedDataSet.GetXml)
 
 
        Response.Clear()
        Response.ContentType = "text/xml"
        Response.ContentEncoding = Encoding.UTF8
        Response.Write(xmlDocument.InnerXml)
        Response.Flush()
        Response.End()
 
    End Sub
 
End Class
Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Reddit
  • Technorati
  • Facebook
  • Google Bookmarks
  • LinkedIn

→ No CommentsTags:···