Tuesday 31 July 2012

How to Change Permission of Folder in Visual Basic / C#

VB.NET Set Folder Permission / C# 
Set Folder Permission 
Allow/Deny

In this snippet we create a new directory and set the permission of it to Fullcontrol using ACL.

 VB code
 Private Shared Sub ChangePermissionOfDir()
        'Folder
        Dim NewDirectory As DirectoryInfo = Directory.CreateDirectory("C:\Test001")

        Dim dSecurity As DirectorySecurity = NewDirectory.GetAccessControl()

        Dim fAccess As New FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Deny)

        dSecurity.AddAccessRule(fAccess)

        NewDirectory.SetAccessControl(dSecurity)
 

    End Sub
 

 C# code
private static void ChangePermissionOfDir()
{
    //Folder
    DirectoryInfo NewDirectory = Directory.CreateDirectory("C:\\Test001");
 

    DirectorySecurity dSecurity = NewDirectory.GetAccessControl();

    FileSystemAccessRule fAccess = new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Deny);

    dSecurity.AddAccessRule(fAccess);

    NewDirectory.SetAccessControl(dSecurity);
}

How to create DataTable on the fly and add Rows (data) using VB.NET/C#


How to Populate DataGridView on the fly using VB.NET

Not all data come from a database table;
at times we need to create in on the fly.
we create a datatable and then create appropriate data columns.

Tested Code..

Dim oDataTable As New DataTable("CustomerInfo")
        Dim oDR As DataRow

        oDataTable.Columns.Add(New DataColumn("Name"))
        oDataTable.Columns.Add(New DataColumn("Date"))
        oDataTable.Columns.Add(New DataColumn("Address"))
        oDataTable.Columns.Add(New DataColumn("ContactNum"))
 ….

Then data row is created and added to the table


  oDR = oDataTable.NewRow
        oDR("Name") = "shree"
        oDR("Date") = Now.ToString()
        oDR("Address") = "Gujarat"
        oDR("ContactNum") = "09898989898"

        oDataTable.Rows.Add(oDR)

This can be continued till all rows are added;

DataGridView is then bound to the datatable using DataSource property

  DataGridView1.DataSource = oDataTable
        DataGridView1.AutoResizeColumns()

Which gives you the screen below


 
--------------------------------------------------------------------------------
Public Class Form1

    Private Sub Form1_Load(sender As System.Object,
 e As System.EventArgs) Handles MyBase.Load

        CreateOnTheFlyDataTable()
    End Sub

    Sub CreateOnTheFlyDataTable()
        Dim oDataTable As New DataTable("CustomerInfo")
        Dim oDR As DataRow

        oDataTable.Columns.Add(New DataColumn("Name"))
        oDataTable.Columns.Add(New DataColumn("Date"))
        oDataTable.Columns.Add(New DataColumn("Address"))
        oDataTable.Columns.Add(New DataColumn("ContactNum"))

        oDR = oDataTable.NewRow
        oDR("Name") = "shree"
        oDR("Date") = Now.ToString()
        oDR("Address") = "Gujarat"
        oDR("ContactNum") = "09898989898"

        oDataTable.Rows.Add(oDR)
        DataGridView1.DataSource = oDataTable
        DataGridView1.AutoResizeColumns()
    End Sub
End Class

Monday 9 July 2012

Create 30 Days Trial Version with ProductKey Application

Create 30 Days Trial Version Windows Application With Product Key


Imports System.Windows.Forms

Public Class ProdVersoin
 

Private Sub ProdVersoin_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

If My.Settings.Register = True Then
            MainMdi.Show()
            Me.Close()
        End If

        lblCurrentdate.Text = DateTime.Now

        If My.Settings.Exdate = Nothing Then
            My.Settings.Exdate = DateTime.Now.AddDays(30)
        Else

        End If
        lblExdate.Text = My.Settings.Exdate

 End Sub

Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
 If TextBox1.Text = "123-456-789" Then
            My.Settings.Register = True
            MainMdi.Show()
            Me.Close()
        Else
            MsgBox("Wrong " + TextBox1.Text + " Activation Key, Retry..!!")
        End If

End Sub

Public Sub RefreshTime()
        lblCurrentdate.Text = DateTime.Now
End Sub

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        RefreshTime()
        If DateTime.Now > My.Settings.Exdate Then
            lblError.Text = "Sorry, Your Product Has Expired. Enter Product Your " + vbNewLine + "Product Key for Register or get Full Version!!"

End If
End Sub

-This cede is basically tested. It will work..