|
File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden)
You can set whatever attributes you like, but you can't cause users who go looking to be unable to access the file, unless your program is logged in as admin, and they are not.
BTW, that C# code above, you'll have to convert it ( change | to OR, etc )
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Thanks for the reply Christian. I came accros FileIOPermission in VS.NET help. Could this be use to accomplish what I want to do? I tried the following but it had no impact as far as I can tell.
Dim fileIOPerm1 As FileIOPermission
fileIOPerm1 = New FileIOPermission (FileIOPermissionAccess.NoAccess, "D:\test.txt")
fileIOPerm1.AllFiles = FileIOPermissionAccess.NoAccess
Thanks,
|
|
|
|
|
The MSDN on this is here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemsecuritypermissionsfileiopermissionclasstopic.asp[^]
Personally, I'm not sure how it could work globally - on what basis are you providing this permission ? Surely if you removed access to all files across all of Windows, the OS would crash and you'd never be able to log in again ?
Reading it, I think it allows you to specify what files the currently logged in user can access via operations of the File class, i.e. within your code only. That makes sense to me.
Making the files hidden is the best you're going to do IMO. If you deny them access, how is your code ( which runs under their security ) going to read or use it ? If the file is hidden and they find/mess with it, it's their problem. Hell, even if it wasn't hidden, it's their problem.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Thanks Christian. I appreciate your help on this.
Zenu
|
|
|
|
|
Even if you hid the file, they would still have access to it. The only thing that will take away all access rights would be using NTFS permissions. But, you have a huge problem! It is possible for your application to take away the rights to the file, but impossible for it to get them back. The application runs in the security context of the user who launched it. Once this person gives up all his/her access rights to a file, there is not enough rights left to get access to it back.
Like Christian said, it's up to the user to behave around these files. If not, he/she shoot themselves in the foot and that's not your problem.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi I was wondering if anyone out there could point me in the right direction. I am attempting to create custom controls that would be allow for the binding of data. Eg.the checked list box. This control does not allow a user to bind data from a dataset through the properties section of a control. I am looking to bind the checked list box and listview controls in VB.net. Thank you.
|
|
|
|
|
Hi... I am a new user of VB.net so I appreciate this forum.
I am trying to set the DataSource for a DataGrid control on my form using code. Very straight forward question with a very straight forward answer that works well:
Me.daDataAdapterName.Fill(Me.DsDataSourceName.StoredProcedureName_SEL)
However, the DataAdapter and the DataSource for the Datagrid may change based on values from an underlying SQL Table. I want to set the DataAdapter and the DataSource to be based on values from this Table.
This is a very straight forward question and I have properly identified the values that I want and declared them as variables. Now, I want to use the variables in the appropriate statement when declaring the DataAdapter and DataSource for the Datagrid. Being that my background is in VBA, I would have used the following syntax:
Dim V1 as String (Whatever the Name of the DataAdapter is)
Dim V2 as String (Whatever the Name of the DataSet is)
Me." & V1 & ".Fill(Me." & V2 & " .NameofStoredProcedure)
This syntax does not work. What is the appropriate syntax for VB.net?
I have tried variations...
Me.[" & V1 & "].Fill(Me.[" & V2 & "] .NameofStoredProcedure)
and
Me.[" + V1 + "].Fill(Me.[" + V2 + "] .NameofStoredProcedure)
Nothing seems to work.
Suggestions would be greatly appreciated.
Thanks in Advance
Pat
|
|
|
|
|
You're wasting your time. You can't do what your looking at doing. On top of that, there is no reason to do it either.
What is this code trying to accomplish? I mean over and above needlessly trying to change the name of a variable...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave...
The code is trying to accomplish the following:
I am a firm believer in ComboBoxes to enter data. Whether you agree with this approach or not, is not the issue. All of my Comboboxes are limit to list – for very good reason. Accordingly, there must be some provision so the user can enter new choices into the database:
Method:
Historically (in VBA in MS Access) my method is pure simplicity: 1 Form, 1 Combobox, 1 Subform (Datasheet view), 1 SQL Table
• The Subform and all of its cells are unbound
• The layouts for the Subform, (Datasource, Number of columns, widths, etc) are set from a single DataTable.
• If the user wants to enter a new “City”, he/she chooses City in main Combobox
• Based on the value of the Combobox, a single record in the Table is accessed.
• This record provides information on how to setup the Subform (the number and widths of the columns, datasource etc)
• All of the existing choices then appear in the subform and the user is then able to make the necessary edits/additions.
Using VB.net: 1 Form, 1 Combobox, 1 Datagrid, 1 SQL Table.
• The Datagrid has no Datasource
• The Based on the choice from the single ComboBox, a SQL Table is accessed.
• This record provides information on how to setup the Datagrid (DataAdapter, DataSource, Stored Procedure, the number and widths of the columns, etc)
• All of the existing choices then appear in the Datagrid and the user is then able to make the necessary edits/additions.
This may sound complicated, in fact, it would be as simple as defining two variables (V1 and V2):
• Where V1 is the name of the DataAdapter.
• Where V2 which is the name of the Dataset.
Declaring these variables along with their appropriate values is easy but it brings me back to my original question… What is the proper syntax?
Me.V2.StoredProcedure.Clear() (Normally would read… Me.NameOfDataSource.StoredProcedure.Clear)
And
Me.V1.Fill(Me.V2.StoredProcedure) (Nomally would read…
Me.NameofDataAdapter.Fill(Me.NameofDataSource.StoredProcedure))
I am not trying to needlessly change a Variable. However, if I can set the DataAdapter, DataSource, columns, etc, for over 25 choices from a single form and a single Datagrid, then I have...
• far fewer controls;
• fewer datagrids (1 vs 25);
• a single place to add/edit Master List choices;
• less code to write/edit/maintain (a single function that contains roughly 25 lines of code)
• BUT the real beauty of this is that if I want to add another ComboBox to my application, I simply add a single record in the SQL Table identifying the appropriate DataAdapter, DataSource, Number and Widths of Columns, etc. I then add or modify a single DataAdapter and I am ‘good to go’
This is why I am wondering about a simple little piece of code although, I guess I could have 25 datagrids layered on the form.
Thanks
Pat
|
|
|
|
|
Capilano wrote:
I am a firm believer in ComboBoxes to enter data. Whether you agree with this approach or not, is not the issue.
Excuse me, but when did I say using ComboBoxes was a bad idea?
Capilano wrote:
Historically (in VBA in MS Access) my method is pure simplicity: 1 Form, 1 Combobox, 1 Subform (Datasheet view), 1 SQL Table
• The Subform and all of its cells are unbound
• The layouts for the Subform, (Datasource, Number of columns, widths, etc) are set from a single DataTable.
• If the user wants to enter a new “City”, he/she chooses City in main Combobox
• Based on the value of the Combobox, a single record in the Table is accessed.
• This record provides information on how to setup the Subform (the number and widths of the columns, datasource etc)
• All of the existing choices then appear in the subform and the user is then able to make the necessary edits/additions.
Using VB.net: 1 Form, 1 Combobox, 1 Datagrid, 1 SQL Table.
• The Datagrid has no Datasource
• The Based on the choice from the single ComboBox, a SQL Table is accessed.
• This record provides information on how to setup the Datagrid (DataAdapter, DataSource, Stored Procedure, the number and widths of the columns, etc)
• All of the existing choices then appear in the Datagrid and the user is then able to make the necessary edits/additions.
This may sound complicated, in fact, it would be as simple as defining two variables (V1 and V2):
• Where V1 is the name of the DataAdapter.
• Where V2 which is the name of the Dataset.
Declaring these variables along with their appropriate values is easy but it brings me back to my original question… What is the proper syntax?
This is what we needed! But, there is no proper syntax. What you want to do is possible, just not how you want to do it. You have to rethink your logic to use collections of objects, like a collection of DataAdapters. It's impossible to use "variable variable names".
A hash table can hold on to all the DataAdapters you want, in a key/value, or in your case, key/object, pair. The key will be the name of the adapter, and the object will, of course, be the dataadapter.
Hashtable Class[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Using variables probably won't work. You might have to resort to the old fashioned Select Case
Select variableName
..case V1
....dataAdapter code
....dataSet code
..case V2
....dataAdapter code
....dataSet code
.
.
.
end select
|
|
|
|
|
In my sql database, it's a binary value, when it binding to datagrid, it shows up "Ture" or "False". How can I change it output to "active" or "inactive"? Is there any way to do it? Thanks.
Lisa
|
|
|
|
|
Can you add a table to your database with the values you want and then join it to your current table(s)in the dataAdapter?
If you can't add the table to the current database, you make a separate database with the new table. I have seen instructions on joining tables from different databases
|
|
|
|
|
|
Hi,
If any body can give me a vb script code for reading all the messages that are there in an IBM MQ queue( of any type), I will be very thankful to you. Scenario is like this - Suppose the application fails and messages are getting logged into the queue, I have to read these logged messages from queue into a text file.
Thanks in Advance
Nasir
|
|
|
|
|
Hello.....
how can i get the MX Entries of a Domain???
Thanks....
|
|
|
|
|
What? Are you talking about DNS records or Active Directory?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
when i add a record in database the record is added.
but it does not shows the record when i press move next or prev. button. when i close the form and run again then it
display the added record. plz help me
'code
str = "insert into agent(agentid,agentname) values('" & txtagentid.Text & "','"& txtname.Text & "' )"
ds = dbcon.InsertDS(ds, str) 'insert record into database
ds.AcceptChanges()
ds.GetChanges(DataRowState.Added)
MessageBox.Show("One Record Added")
i am software engineer
|
|
|
|
|
Hi
From the code which you have posted it seems that you are updating the dataset. Updating the dataset wont update the database.
when you refresh the form the dataset is loaded again from that database so u dont see the necessary changes in the datagrid.For your requitement why dont you try the Following code
Private WithEvents daemp As New SqlDataAdapter("select * from emp",cn)
'Write this code whereever you are populating the dataset which can
'be a load button
Dim ds As New DataSet
daemp.Fill(ds, "emp")
dgemp.DataSource = ds.Tables(0)
'once u make changes u need to save the chages write this code in \
'next prev pageindexchanged code...also write it in save
Dim dt As New DataTable
dt = dgemp.DataSource
Try
'updating the database with dataadapter using new dataset table
daemp.Update(dt)
MessageBox.Show("update done")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
'this is event if you insert wrong data
Private Sub daemp_RowUpdated(ByVal sender As Object, ByVal e As System.Data.SqlClient.SqlRowUpdatedEventArgs) Handles daemp.RowUpdated
If e.Status = UpdateStatus.ErrorsOccurred Then
e.Row.RowError = "mandar says error"
e.Status = UpdateStatus.Continue
End If
End Sub
Hope this helps
Mandar Patankar
Microsoft Certified professional
|
|
|
|
|
I have Groupboxes placed on the TabPages of a TabControl in VB.Net. These Groupboxes contal Textboxes to be loaded from a Combo SelectedIndex event. When the choice of the combo is made, the textboxes are filled, but as soon as you move from one tabpage to the other, the contents of the textbox is lost. How can I preserve what has been loaded into these texboxes and work on the form until I apply my insert Command?
Please I need your help
Derick Fontah
|
|
|
|
|
in vb.net,what's significant differences from vb 6.0 and how are powerfull vb.net compared by borland delphi version up to 7.0?
thanks for your comments.
|
|
|
|
|
|
One very significant difference you should be aware of:
VB6 requires you to deploy a minimum runtime file set that is about ~1.5 MB setup file size.
VB.NET requires you to deploy the NET framework which is about ~30 MB setup file size.
Robert
|
|
|
|
|
Still having same problem... Here is a less confusing version I think. I renamed everything back to default (more or less) I am trying to filter my TempData table (MS Access) by a value and have the new data reflected in the MainDataSet1 instance. I know im still far off, but I feel that im getting closer. (Later the fixed string '11x14' will be a variable based on the combobox)
and yes I know that this code doesnt work... that is my problem... its a major hack job
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
OleDbSelectCommand1.CommandText = "SELECT TemplateID, Images, ImageSize, ID FROM TempData WHERE ImageSize = '11x14'"
OleDbSelectCommand1.Connection = OleDbConnection1
OleDbConnection1.Open()
OleDbSelectCommand1.ExecuteReader()
OleDbConnection1.Close()
OleDbAdapter.SelectCommand = OleDbSelectCommand1 '"SELECT TemplateID, Images, ImageSize, ID FROM TempData WHERE ImageSize = '11x14'"
OleDbAdapter.Fill(MainDataSet1.TempData)
End Sub
Any help is appreciated. I WILL learn this or go totally insane.
|
|
|
|
|
I dont care what they say.. hacking code does work!
Sub Picker_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim LicForm As New LicForm()
OleDbSelectCommand1.CommandText = "SELECT TemplateID, Images, ImageSize, ID FROM TempData WHERE ImageSize = '" & LicForm.Aspect & "'"
MainDataSet1.Clear()
OleDbAdapter.Fill(MainDataSet1)
'If LicForm.Aspect = "" Then MsgBox("oops", MsgBoxStyle.Information)
Initialize()
End Sub
Sub Initialize()
Dim ImageList1 As New ImageList()
Dim Counter As Integer
Dim Path As String
ImageList1.Images.Clear()
ListView1.Items.Clear()
ImageList1.ImageSize = New Size(128, 64)
MsgBox(MainDataSet1.TempData.Count, MsgBoxStyle.Information)
For Counter = 1 To MainDataSet1.TempData.Count
Path = MainDataSet1.TempData(Counter - 1).TemplateID
ImageList1.Images.Add(Image.FromFile("C:\Adobe Project\Icons\" & LicForm.Aspect & "\" & Path & ".jpg"))
ListView1.Items.Add(Path)
Next Counter
ListView1.LargeImageList = ImageList1
For Counter = 0 To MainDataSet1.TempData.Count - 1
ListView1.Items(Counter).ImageIndex = Counter
Next Counter
ListView1.View = View.LargeIcon
ListView1.Update()
Me.Update()
End Sub
I just wanted to post this update to say "Yeah!" and so anyone who didnt understand the original question would now maybe see. Thanks again all and I will be here all week long.
and yes there will be further refinements.. this is my initial working copy
|
|
|
|
|