|
I am trying to create a program that allows users to create new folders and set security permissions. Any help would be greatly appreciated. VBV.NET/ NET Framework 2.0
|
|
|
|
|
If you Import System.IO
You will have access to the Directory object.
You can do a Directory.CreateDirectory(path, directorySecurity)
where path is your new folder
and directorySecurity is the directory security for the folder.
Here some sample code from Microsoft help on directorysecurity:
Imports System
Imports System.IO
Imports System.Security.AccessControl
Module DirectoryExample
Sub Main()
Try
Dim DirectoryName As String = "TestDirectory"
Console.WriteLine("Adding access control entry for " + DirectoryName)
' Add the access control entry to the directory.
AddDirectorySecurity(DirectoryName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow)
Console.WriteLine("Removing access control entry from " + DirectoryName)
' Remove the access control entry from the directory.
RemoveDirectorySecurity(DirectoryName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow)
Console.WriteLine("Done.")
Catch e As Exception
Console.WriteLine(e)
End Try
Console.ReadLine()
End Sub
' Adds an ACL entry on the specified directory for the specified account.
Sub AddDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
' Create a new DirectoryInfoobject.
Dim dInfo As New DirectoryInfo(FileName)
' Get a DirectorySecurity object that represents the
' current security settings.
Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
' Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(New FileSystemAccessRule(Account, Rights, ControlType))
' Set the new access settings.
dInfo.SetAccessControl(dSecurity)
Hope that helps.
Ben
|
|
|
|
|
I am new to VB.Net 2005, is there anyone who can help, I am trying to send text message to a wireless pager from my work PC. My SMTP server will not allow this due to NetworkCredential. Here is the code i am using that just will not work.
mail.From = New MailAddress("email address@my.company")
mail.To.Add("email address@my.company")
Dim mailClient As New SmtpClient
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("network login Name", "network password", "name of my smtp server")
mail.To.Add("mypager#@usamobility.net")
mailClient.Host = "my.server"
mailClient.UseDefaultCredentials = False
mailClient.Credentials = basicAuthenticationInfo
mailClient.Send(mail)
|
|
|
|
|
|
Is it possible to launch an exisitng MS access database (Test.mdb) from my VB6?
Sub OPEN_ACCESS()
Dim oApp As Object
Dim OPEN_ACCESS
OPEN_ACCESS = "T:\ACCESS\TEST.mdb"
Set oApp = CreateObject("ACCESS.Application")
oApp.Database.Open (OPEN_ACCESS)
oApp.Visible = True
End Sub
|
|
|
|
|
I'm developing a project on Visual Studio 2005 and I need to publush it on a web page. I'm using this HTML code:
<object
id="eDataMan"
name="eDataMan"
classid="http:eDataMan.dll#eDataMan.eDataMan"
style="width:100%; height:100%; background-color:ButtonFace; font-family:Arial; font-size:x-
small">
</object>
But all I get is a picture icon on the web page, the program does not run.
I'm using Component One True DBGrid control on my project
This is what I have on my VB.NET project:
Modulo objsafe.vb:
-----------------------------------------------------
Imports System.Runtime.InteropServices
Module objsafe
<ComImport()> _
<Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064")> _
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IObjectSafety
Function GetInterfaceSafetyOptions(ByRef iid As Guid, ByRef pdwSupportedOptions As Integer, ByRef pdwEnabledOptions As Integer) As Integer
Function SetInterfaceSafetyOptions(ByRef iid As Guid, ByVal dwOptionSetMask As Integer, ByVal dwEnabledOptions As Integer) As Integer
End Interface
End Module
-----------------------------------------------------
Control eDataMan.vb:
-----------------------------------------------------
Public Class eDataMan
'Inherits Windows.Forms.UserControl
Implements IObjectSafety
' Constants for implementation of the IObjectSafety interface
Private Const INTERFACESAFE_FOR_UNTRUSTED_CALLER As Integer = &H1
Private Const INTERFACESAFE_FOR_UNTRUSTED_DATA As Integer = &H2
Public Function GetInterfaceSafetyOptions(ByRef iid As Guid, ByRef pdwSupportedOptions As Integer, ByRef pdwEnabledOptions As Integer) As Integer Implements IObjectSafety.GetInterfaceSafetyOptions
pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER Or INTERFACESAFE_FOR_UNTRUSTED_DATA
pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER Or INTERFACESAFE_FOR_UNTRUSTED_DATA
Return 0
End Function
Public Function SetInterfaceSafetyOptions(ByRef iid As Guid, ByVal dwOptionSetMask As Integer, ByVal dwEnabledOptions As Integer) As Integer Implements IObjectSafety.SetInterfaceSafetyOptions
Return 0
End Function
Private Sub eDataMan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO CODE
MsgBox("I'm here")
End Sub
End Class
-----------------------------------------------------
-- modified at 12:02 Thursday 8th March, 2007
|
|
|
|
|
Private Sub CheckZeroRecord()
With clsEmpDependant
If ZeroRecord(cTbl_EmpDependatHead, Cnn) = False Then
If .MoveRecord(Employee_Module.GotoRecord.PreviousRecord, HelpBoxEmployeeName.get_HelpCode() & txtDocumentNo.Text) = True Then DisplayRecord() : GoTo procExit
If .MoveRecord(Employee_Module.GotoRecord.NextRecord, HelpBoxEmployeeName.get_HelpCode() & txtDocumentNo.Text) = True Then DisplayRecord() : GoTo procExit
If .MoveRecord(Employee_Module.GotoRecord.FirstRecord, "") = True Then DisplayRecord() : GoTo procExit
End If
NavigationBar.AddNewRecord()
AddRecord()
End With
procExit:
End Sub
----------------------------------------------------------------------------------------------------
I wrote the above code in Visual Basic.Now I upgraded it to Visual Basic.Net but it gives this Error Message:(Statement cannot appear within method body.End of method assumed).It will now underline Private Sub.
please help me out.
Thanks.Ademola
-- modified at 10:08 Thursday 8th March, 2007
|
|
|
|
|
This is because you tried to do something like this:
Private Sub Method1()
.
.
.
Private Sub Method2()
.
.
.
End Sub
.
.
.
End Sub
You tried to define a method inside another method. Obviously, you can't do that.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
hi i have to do a application i have to find a text given as input in the richtextbox
but i am not able to do that as its not points the cursor to the point where the text has to be find is there
with regards
Balagurunathan.B
|
|
|
|
|
balakpn wrote: but i am not able to do that as its not points the cursor to the point where the text has to be find is there
That's because you have to write the code that highlights the found text. It doesn't happen automatically.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
i am not able to find that will u help me
with regards
Balagurunathan.B
|
|
|
|
|
What do you mean "not able to find that"? Of course you can't find it, you haven't written it yet!
Start with the Find() method of the RichTextBox. It'll return the text position of the first occurance of whatever you want to find. You the use that value to set the RTB's SelectionStart property and the length of your serarch term to set the SelectionLength property to highlight the text. Then call the RTB's ScrollToCaret method to make sure that the user can see the highlight.
The rest is left up to you as an exercise.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
in my application i am using database connection where ever i am opening the connection i have used con.close to close the connection but its not getting closed
with regards
Balagurunathan.B
|
|
|
|
|
.NET uses connection pooling. The connection will stay open in the background and when you create a new connection you'll get the previous (pooled) connection. This saves a lot of time because creating the initial connection can be time consuming.
|
|
|
|
|
so if i want to close it means wat i have to do
why i am asking is then only i can continue the next process
it is must for my project
with regards
Balagurunathan.B
|
|
|
|
|
What process? Why do you have to do this?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
in my application i will be using many temporary tables and later if i want to give a fresh process without closing the application i have to delete the database as i dono how many tables r there even if i know that it will be a very time consuming one so ineed to close the database and delete it later i will create it .
although its the bad practice i have to do that
with regards
Balagurunathan.B
|
|
|
|
|
I had a similiar issue a while back - I'd be updating thousands of records at a time, but eventually ran into problems with time out errors with SQL. I thought I'd done everything right (followed Microsoft Best Practices)
But the problem was not really with wondering how to forcefully close a connection (my first guess) or to disable connection pooling, it was with how I created the connection in the first place and my management of that connection for the lifetime of the application.
If you've got code that constantly opens and closes a connection to the exact same datasource, I'd maybe rethink that code and only open it once and close it once (with capability to reopen if the connection is lost). I've found that even with connection pooling working and all, when you open a connection more than once, more than one connection is created to the data source.
|
|
|
|
|
so i have to open it once and have to close the connection only once is it
with regards
Balagurunathan.B
|
|
|
|
|
Depends on how you are using the connection really - I find that if I am using a database connection that I know that has the potential for more than a few transactions I'd think about how I am opening and closing those connections.
What I used todo is open and close a connection on each transaction to the database. This worked fine in most test cases, but as Colin mentioned, it takes time. So as insert would open the connection, do it's stuff and then close. Problem I found was that even though the connection string was exactly the same I'd be creating something like 20 connections into the database for the one instance of the application. Maybe it was something dodgy in my code (most likely)!
When you need to update records in the thousands or millions, this is just really in-efficient.
Then I went to opening the connection when the class used to represent the database (in a nutshell) was instaniated, then closed in the destructor. This works fine now and even in a tiered architecture (albeit with some changes) it generally scales quite well.
|
|
|
|
|
Hi, I hope some one can help. I have a really sill query.
I am new to VB and need some help.
How do i asign the date to a variable?
I have tryed utilising "date" and "datetime" but they return zero values
If someone could please help me with the syntax I would be very greatful. Thanks Jon
|
|
|
|
|
|
he means:
YourString = DateTime.now
Posted by The ANZAC
|
|
|
|
|
Dim dtmDate As DateTime
dtmDate = DateTime.Now()
label1.Text = dtmDate.ToString("D")
Magesh
|
|
|
|
|
Thank you for the responses they have helped no end. Jon;)
|
|
|
|