|
Here are my two functions that I call under button click:
Public Function CreateZip(ByVal source As String, ByVal destination As String) As Boolean
If (Not (File.Exists(source))) Then
Return False
End If
If (Not (Directory.Exists(destination))) Then
Return False
End If
Try
Dim fastZip As FastZip = New FastZip
fastZip.CreateZip(destination, source, True, "", "")
Catch
Return False
End Try
Return True
End Function
Public Sub Folder()
Dim dirName As String = DateTime.Now.ToString("MM_dd_yyyy hh.mm.ss")
Dim fullPath As String = Path.Combine("C:\Data Feeds\Backup\", dirName
If (Not (Directory.Exists(fullPath))) Then
Directory.CreateDirectory(fullPath)
ElseIf (Directory.Exists(fullPath)) Then
Directory.CreateDirectory(fullPath(2))
End If
End Sub
I want to know how to copy the destination folder to the fullPath folder when it is created.
jds
|
|
|
|
|
Jds,
there doesn't seem to be a vb.net way that doesn't involve enumerating through all the folders and files. I can give you that code if you want it.
the quick way would be to do the following...
Dim fso As Object
fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFolder("C:\test", "c:\temp\")
fso = Nothing
copies the folder "test" into c:\temp\ resulting in c:\temp\test\
|
|
|
|
|
I got the following error: Exception from HRESULT: 0x800A004C (CTL_E_PATHNOTFOUND)which highlighted this line of code: fso.CopyFolder("C:\test.zip", "C:\Data Feeds\Backup\").
Any ideas?
jds
|
|
|
|
|
jds,
it looks like your trying to treat the file as a folder. the method copyfolder will only work with 2 folders (source/destination). your trying to make the zip file a folder (seemingly).
file.copy("c:\test.zip","C:\Data Feeds\Backup\test.zip",true) '<--should take care of the copying.
sorry-->my understanding is that you were trying to copy 1 directory and all it's subfolders into another.
nathan
|
|
|
|
|
Sorry,
I am trying to copy 1 directory and all it's subfolders into another. I already have the zip folder created with its folders and subfolders through code and I have the code to create a dated folder in another procedure which will be the backup folder. Once I click the button to create the zip folder I want the backup folder to be created containing that zippped folder.
Thanks!
jds
|
|
|
|
|
I maybe way off but you seem to have the answer in your code that you gave. pass in the variable "fullPath" into your function that creates the zip as the destination
Dim dirName As String = DateTime.Now.ToString("MM_dd_yyyy hh.mm.ss")
Dim fullPath As String = Path.Combine("C:\Data Feeds\Backup\", dirName)
Dim fastZip As FastZip = New FastZip
fastZip.CreateZip(fullPath, source, True, "", "")
won't the create a zip of whatever the source is into fullpath?
|
|
|
|
|
No, that doesn't work. The "test.zip" folder is already located in c:\. Remember, these are two different sub procedures. I want that test.zip folder to be copied to the dated folder which I create with the code below as a backup:
Public Sub BackupFolder()
Dim dirName As String = DateTime.Now.ToString("MM_dd_yyyy hh.mm.ss")
Dim fullPath As String = Path.Combine("C:\Data Feeds\Backup\", dirName)
If (Not (Directory.Exists(fullPath))) Then
Directory.CreateDirectory(fullPath)
ElseIf (Directory.Exists(fullPath)) Then
Directory.CreateDirectory(fullPath(2))
End If
End Sub
Hope I explained this accuratley.
jds
|
|
|
|
|
I think theres some confusion going on. Test.Zip is not a folder. You can't navigate through it and treat it like a folder in your code. It MUST be treated as a file. The only reason you can do so in Explorer is because there is a Shell extension giving you the illusion of a navigable file system in the ZIP file.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
pls can someone direct me how to connect to access database using VB.Net
john
|
|
|
|
|
This[^] should be all you need.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello Everyone.
I hope someone can help me with this problem. i have a datatable bound to a bindingsource, and i display its content through a datagridview in this way:
bindingSource1.DataSource = dataTable1
dataGridView1.DataSource = bindingSource1
My problem is that when i update the data contained in the table through the bindingsource, my datagridview does not refresh and keeps displaying the old values. but the strangest thing is that if i manually sort the datagridview by clicking a column header, the datagrid refreshes and displays the updated values. this occurs only if i manually click on the headers, it does not work if i sort the grid in the code or if i call datagridview1.refresh()
I desperately need the datagrid to update its values as i update the bindingsource, without clicking anything. how can i do that?
Thanks in Advance,
Rey9999
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|
|
Have you tried calling Control.Invalidate(), then calling Control.Update() ?
The sequence of these two method calls should force the DataGridView to redraw itself.
|
|
|
|
|
Sebrell wrote: Have you tried calling Control.Invalidate(), then calling Control.Update() ?
The sequence of these two method calls should force the DataGridView to redraw itself.
i tried but i still have the same problem...
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|
|
so much for the simple answer...
I'm reminded of a similar problem I once had with a RichTextBox, where I needed to force it to redraw its scroll-bars. I solved that problem by writing a method along the lines of the following:
(C# code, sorry)
private void Jiggle() {
if (this.Orientation == Orientation.Horizontal) {
this.rtfBox.Width -= 3;
this.rtfBox.Width += 3;
} else {
this.rtfBox.Height -= 3;
this.rtfBox.Height += 3;
}
this.rtfBox.Invalidate();
}
I then called this method from the method that needed to redraw the RichTextBox (which was a property setter for a container control). I was surprised how well it worked. Especially since the RichTextBox in question had its Dock property set to DockStyle.Fill.
I'd suggest dynamically changing, by a small number of pixels (fewer than 8), the Width of one of the ColumnHeaders in your DataGridView, since it works when you click it. Or to change the Sort column to a different column, then back to the original column.
HTH
Sebrell
-- modified at 14:30 Wednesday 18th October, 2006
|
|
|
|
|
i'll try, thanks
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|
|
I found the solution by chance... i realized i was updating the bindingsource's datasource instead of the bindingsource itself. may i be cursed eternally for my mistake
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|
|
I have down loaded the following code form Microsoft site and it is working.
But I am unable to understand how I will trap it in my keyup or keypress event or any other way.
Can any body help me please.
With regards
Suman
How to trap keystrokes in .NET controls by using Visual Basic .NET or Visual Basic 2005
View products that this article applies to.
On This Page
SUMMARY
Set Up the Key Trap
Implement the Overridden Method
Build an Example
SUMMARY
This step-by-step article demonstrates how to trap keystrokes in Windows Forms controls. By using the sample code in this article, you can intercept almost any individual keystroke. You also can intercept key combinations, including CTRL and ALT. The Print Screen key is not affected by this technique. Additionally, some keystrokes from keyboards with additional keys, such as keys that control a Web browser or a CD-ROM player, might not be captured.
For most purposes, the standard KeyUp, KeyDown, and KeyPress events are enough to capture and handle keystrokes. However, not all controls raise these events for all keystrokes under all conditions.
For example, consider the DataGrid control: If no data has been assigned to the grid, the arrow keys (LEFT ARROW, RIGHT ARROW, UP ARROW, and DOWN ARROW) raise only the KeyUp event. Other keys, such as A or 4, raise all three events. If the DataGrid is currently displaying data, none of the standard keyboard events are raised for the navigation keys. Keystrokes such as A or 4 raise no events, raise only KeyUp, or raise all three events, depending on what is currently selected in the control. In these situations, you can follow the steps in this article to capture keystrokes, regardless of the state of the control.
The code samples in this article are written to work with the DataGrid, because this is the control for which this feature is most frequently requested. You can use this same approach with other .NET controls.
Set Up the Key Trap
To trap keystrokes in a Windows Forms control, you derive a new class that is based on the class of the control that you want. You override the ProcessCmdKey method. In this overridden method, you will place the code to process the keystrokes that you want to trap. The following sample code is an example of the basic structure for such a class:
Class MyDataGrid
Inherits DataGrid
Protected Overrides Function ProcessCmdKey( ByRef msg As Message, ByVal keyData As Keys ) As Boolean
End Function
End Class
Implement the Overridden Method
The system passes two parameters to the ProcessCmdKey method: msg and keyData. The msg parameter contains the Windows Message, such as WM_KEYDOWN. The keyData parameter contains the key code of the key that was pressed. If CTRL or ALT was also pressed, the keyData parameter contains the ModifierKey information.
Using the msg parameter is not mandatory; you can ignore it. It is good practice, however, to test the message. In this example, you test WM_KEYDOWN to verify that this is a keystroke event. You also test WM_SYSKEYDOWN, so that it is possible to catch keystroke combinations that involve control keys (primarily ALT and CTRL).
To trap specific keys, you can evaluate the keyCode by comparing it to the Keys enumeration. The following code sample demonstrates how to catch the keystrokes UP ARROW, DOWN ARROW, TAB, CTRL+M, and ALT+Z:
Const WM_KEYDOWN As Integer = &H100
Const WM_SYSKEYDOWN As Integer = &H104
If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
Select Case (keyData)
Case Keys.Down Console.WriteLine("Down Arrow Captured")
Case Keys.Up Console.WriteLine("Up Arrow Captured")
Case Keys.Tab Console.WriteLine("Tab Key Captured")
Case (Keys.Control Or Keys.M) Console.WriteLine("<ctrl> + m Captured")
Case (Keys.Alt Or Keys.Z) Console.WriteLine("<alt> + z Captured")
End Select
End If
Build an Example
The following example shows how to trap keystrokes with the DataGrid control.
1.Create a new Windows Control Library project in Visual Basic .NET or in Visual Basic 2005.
2.View the properties for the class UserControl1, and then change the name to MyDataGrid.
3.View the code for the Control Library, and then change the following line of code
Inherits System.Windows.Forms.UserControl
to the following:
Inherits System.Windows.Forms.DataGrid
4.Add the following method to the MyDataGrid class:
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, _ ByVal keyData As Keys) As Boolean
Const WM_KEYDOWN As Integer = &H100
Const WM_SYSKEYDOWN As Integer = &H104
If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
Select Case (keyData)
Case Keys.Down Me.Parent.Text = "Down Arrow Captured"
Case Keys.Up Me.Parent.Text = "Up Arrow Captured"
Case Keys.Tab Me.Parent.Text = "Tab Key Captured"
Case (Keys.Control Or Keys.M) Me.Parent.Text = "<ctrl> + M Captured"
Case (Keys.Alt Or Keys.Z) Me.Parent.Text = "<alt> + Z Captured"
End Select
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
5.Build the project.
6.Create a new Windows Application project in Visual Basic .NET or in Visual Basic 2005. By default, Form1 is created.
Note You must change the code in Visual Basic 2005. By default, Visual Basic creates two files for the project when you create a Windows Forms project. If the form is named Form1, the two files that represent the form are named Form1.vb and Form1.Designer.vb. You write the code in the Form1.vb file. The Windows Forms Designer writes the code in the Form1.Designer.vb file. The Windows Forms Designer uses the partial keyword to divide the implementation of Form1 into two separate files. This behavior prevents the designer-generated code from being interspersed with your code.
For more information about the new Visual Basic 2005 language enhancements, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnhcvs04/html/vs04k1.asp
For more information about partial classes and the Windows Forms Designer, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-us/library/ms171843.aspx7. On the Tools menu, click Customize Toolbox.
8.Click the .NET Framework Components tab.
9.Click Browse, find the control/DLL that was just created, and then click OK.
10.The control MyDataGrid now appears in the toolbox. Place one on Form1.NOTE: You can use the code in the remaining steps to create sample data for the grid to display.
11.Add the following code to the namespace of the Form. You can place the code either before or after the Form Class definition.
' Structure is to provide sample data for the example.
Public Structure gridData
Private mmake As String
Private myear As Integer
Public Sub New(ByVal n As String, ByVal y As Integer)
mmake = n
myear = y
End Sub
Public Property Make() As String
Get
Return mmake
End Get
Set(ByVal Value As String)
Make = Value
End Set
End Property
Public Property Year()
As Integer
Get
Return myear
End Get
Set(ByVal Value As Integer)
myear = Value
End Set
End Property
End Structure
12.Add the following code to the form class immediately following the "Windows Form Designer generated code" section:
protected dataArray(5) As gridData
13.Add the following code to the Load event of Form1:
' Create some sample data.
dataArray(0) = New gridData("ford", 1999)
dataArray(1) = New gridData("chevrolet", 1999)
dataArray(2) = New gridData("plymouth", 1988)
dataArray(3) = New gridData("honda", 1999)
dataArray(4) = New gridData("fiat", 1987) ' Assign the data to the grid. MyDataGrid1.DataSource = dataArray
14.Run the sample, and try the various keystrokes that are being trapped (UP ARROW, DOWN ARROW, TAB, CTRL+M, and ALT+Z). The caption of the form is updated to show which keystroke was pressed.
|
|
|
|
|
Rey,
Have you tried to do something simple like turning keypreview property of the form on? Inside the form's keypress/keyup events use activecontrol to know what control is receiving the keystrokes.
It's always worked for me in the past...
nathan
|
|
|
|
|
Thnak you Mr. Nathan,It is working.
With Regards
Suman
|
|
|
|
|
Hey Everyone,
I'm pretty familiar with VB.net, but I've never done anything surrounding what I'm trying to do now... I guess it would be called screenscraping. I'm using a java web based app, and what I'm trying to create is a simple app that will take data out of one text field on a form and copy it over to another text field, and then "press" a button on the form. Is any or all of this possible? If you're wondering why I'm looking to do this, the java app I'm using is a testing tool, and I want to populate the actual results text field with the expected results value, and then press the pass step button. It's kind of a pain to copy and paste every single step. So... any help?
Thanks,
Tommy
|
|
|
|
|
Since you're trying to scrape a Java app, your only option is to implement some kind of OCR to read the screen. The Java runtime doesn't use an Win32 handled controls, so there is no way you can use the tricks that would normally work on a Windows application to do the same thing in a Java window.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I would like to create a simple datagrid in VB.net. I have a dataset that I would like to make calculations and then JUST display to the datagrid, no input needed.
Thanks.
|
|
|
|
|
dkoco,
Me.grd.DataSource = ds '<-- dataset
me.grd.DataMember = "tablename" '<-- the table name within your dataset
'---------------------------
'if you don't know the table name you can do this also
me.grd.DataMember = ds.tables(0).tablename
'---------------------------
me.grd.Refresh() '<-- makes the grid load the data in automatically for you
hope this helps
nathan
|
|
|
|
|
Hi All,
I have developed an application which contains a listview control (with 3 columns). I am able to use the LVM_FINDITEM message to finding an item from the first column of the list view control. We need to use this message to find items from the other columns in the listview control.
Shall any one please help me how to find subitems in a listview control suing LVM_FINDITEM message.
Thanks in advance,
Pradeep
|
|
|
|
|
Does it absolutely have to use LVM_FINDITEM? There are other ways of getting information from a listview.
|
|
|
|
|