I want to read a .csv file with hundreds of lines of data. I have created two buttons, one for splitting the file into distinct lines based on their distinct features and the other one for encrypting each of the file and saving two output files.
I have managed to create the methods successfully but merging them is a problem. i.e how do i call the button_split method within the encryption button?
Using my current code, i get this error "Could not find file 'C:\Users\HarrisonPc\Documents\VisualStudio2010\Pr ojects\NewAlgo\NewAlgo\bin\Debug\DO16090001_ABL_MC K058"
Please help.
Thanks - Private Sub SplitFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SplitFolder.Click
-
SplitFolder.Font = New Font(SplitFolder.Font, FontStyle.Italic)
-
Dim openFileDialog1 As New OpenFileDialog()
-
'Setup the open dialog.
-
openFileDialog1.FileName = ""
-
openFileDialog1.Title = "Choose a file to encrypt"
-
openFileDialog1.InitialDirectory = "C:\"
-
openFileDialog1.Filter = "All Files (*.*) | *.*"
-
-
'Find out if the user chose a file.
-
If openFileDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
-
MainModule.strFileToEncrypt = openFileDialog1.FileName
-
txtDestinationEncrypt.Text = MainModule.strFileToEncrypt
-
-
Dim iPosition As Integer = 0
-
Dim i As Integer = 0
-
-
'Get the position of the last "\" in the OpenFileDialog.FileName path.
-
'-1 is when the character your searching for is not there.
-
'IndexOf searches from left to right.
-
While MainModule.strFileToEncrypt.IndexOf("\"c, i) <> -1
-
iPosition = MainModule.strFileToEncrypt.IndexOf("\"c, i)
-
i = iPosition + 1
-
End While
-
-
Dim sr As StreamReader = New StreamReader(MainModule.strFileToEncrypt)
-
Dim strLine As String = String.Empty
-
-
Do While sr.Peek() >= 0
-
strLine = String.Empty
-
strLine = sr.ReadLine
-
Dim reader As StringReader = New StringReader(strLine.ToString())
-
Dim currentRow(1000) As String
-
Dim j As Integer
-
-
While True
-
'For index As Integer = 0 To strLine.Length - 1
-
-
currentRow(j) = reader.ReadLine()
-
-
MessageBox.Show(currentRow(0))
-
' MessageBox.Show(currentRow(1))
-
Dim currentField As String = currentRow(0)
-
Dim delivery_order_number As String = currentField.Split(",")(0)
-
delivery_order_number = delivery_order_number.Replace("""", "").Trim()
-
delivery_order_number = delivery_order_number.Replace("/", "").Trim()
-
-
MsgBox(delivery_order_number)
-
Dim buyer_code As String = currentField.Split(",")(1)
-
buyer_code = buyer_code.Replace("""", "").Trim()
-
MsgBox(buyer_code)
-
Dim warehouse_code As String = currentField.Split(",")(2)
-
warehouse_code = warehouse_code.Replace("""", "").Trim()
-
MsgBox(warehouse_code)
-
-
txtFileDestination.Text = delivery_order_number + "_" + buyer_code + "_" + warehouse_code
-
' Set a variable to the My Documents path.
-
Dim path As String = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
-
Dim outputFile As String = path & "\" & txtFileDestination.Text
-
MsgBox(outputFile)
-
If System.IO.File.Exists(outputFile) = False Then
-
System.IO.File.Create(outputFile).Dispose()
-
End If
-
Dim objWriter As New System.IO.StreamWriter(outputFile, True)
-
objWriter.WriteLine(currentRow(j))
-
objWriter.Close()
-
Exit While
-
-
-
End While
-
-
Exit Do
-
j += 1
-
Loop
-
-
End If
-
End Sub
-
Private Sub EncryptString_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EncryptString.Click
-
EncryptString.Font = New Font(EncryptString.Font, FontStyle.Italic)
-
SplitFolder_Click(sender, e)
-
'Dim openFileDialog1 As New OpenFileDialog()
-
'Setup the open dialog.
-
' openFileDialog1.FileName = ""
-
' openFileDialog1.Title = "Choose a file to encrypt"
-
' openFileDialog1.InitialDirectory = "C:\"
-
' openFileDialog1.Filter = "All Files (*.*) | *.*"
-
-
'Find out if the user chose a file.
-
' If openFileDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
-
' MainModule.strFileToEncrypt = openFileDialog1.FileName
-
MainModule.strFileToEncrypt = txtFileDestination.Text
-
txtDestinationEncrypt.Text = MainModule.strFileToEncrypt
-
-
Dim iPosition As Integer = 0
-
Dim i As Integer = 0
-
-
'Get the position of the last "\" in the OpenFileDialog.FileName path.
-
'-1 is when the character your searching for is not there.
-
'IndexOf searches from left to right.
-
While MainModule.strFileToEncrypt.IndexOf("\"c, i) <> -1
-
iPosition = MainModule.strFileToEncrypt.IndexOf("\"c, i)
-
i = iPosition + 1
-
End While
-
strOutputEncrypt = MainModule.strFileToEncrypt.Substring(iPosition + 1)
-
strOutputEncrypt2 = MainModule.strFileToEncrypt.Substring(iPosition + 1)
-
-
'Assign S the entire path, ending at the last "\".
-
Dim S As String = MainModule.strFileToEncrypt.Substring(0, iPosition + 1)
-
-
'Replace the "." in the file extension with "_".
-
strOutputEncrypt = Me.strOutputEncrypt.Replace("."c, "_"c)
-
strOutputEncrypt2 = Me.strOutputEncrypt2.Replace("."c, "_"c)
-
'The final file name. XXXXX.encrypt
-
txtDestinationEncrypt.Text = S + Me.strOutputEncrypt + ".encrypt"
-
txtDestinationEncrypt2.Text = S + Me.strOutputEncrypt2 + "_encrypted" + ".txt"
-
'End If
-
Dim txtPassEncrypt As String = "this_is_the_key"
-
txtFileToEncrypt.Text = txtPassEncrypt
-
-
-
'Declare variables for the key and iv.
-
'The key needs to hold 256 bits and the iv 128 bits.
-
Dim bytKey As Byte()
-
Dim bytIV As Byte()
-
'Send the password to the CreateKey function.
-
bytKey = CreateKey(txtPassEncrypt)
-
'Send the password to the CreateIV function.
-
bytIV = CreateIV(txtPassEncrypt)
-
-
'Start the encryption.
-
EncryptOrDecryptFile(MainModule.strFileToEncrypt, txtDestinationEncrypt.Text, _
-
bytKey, bytIV, CryptoAction.ActionEncrypt)
-
EncryptOrDecryptFile(MainModule.strFileToEncrypt, txtDestinationEncrypt2.Text, _
-
bytKey, bytIV, CryptoAction.ActionEncrypt)
-
-
-
End Sub
6 1326
Either create your code within functions and call the functions, or you can call a button adding the following line into your encryption button click event: - SplitFolder_Click(sender, e)
Thanks for your response.
I already had called the splitFolder_click method on the second line of EncryptString button
Is your .csv file located within the project directory? It seems that's what it's implying. My apologies for missing that in your code.
I have just saved it within that folder but still gets the same error.
Might the problem be in the path definition? The visual studio is within the MyDocuments folder but have several projects within it. - txtFileDestination.Text = delivery_order_number + "_" + buyer_code + "_" + warehouse_code
-
' Set a variable to the My Documents path.
-
Dim path As String = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
-
Dim outputFile As String = path & "\" & txtFileDestination.Text
-
MsgBox(outputFile)
-
If System.IO.File.Exists(outputFile) = False Then
-
System.IO.File.Create(outputFile).Dispose()
-
End If
-
Dim objWriter As New System.IO.StreamWriter(outputFile, True)
-
objWriter.WriteLine(currentRow(j))
-
objWriter.Close()
I have changed the path
from
Dim path As String = System.Environment.GetFolderPath(Environment.Speci alFolder.MyDocuments)
to
Dim path As String = Directory.GetCurrentDirectory
And it has worked!
Thanks
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Eyal |
last post by:
Hey,
I would appriciate if anyone can help on this one:
I have a java object/inteface having a method with a boolean
parameter. As I'm trying to call this method from a javascript it
fails on...
|
by: MC D |
last post by:
Is it possible to call an objects constructor method from within the class
somehow? The class I have populates itself with data from a sqlServer
database when it is constructed, and I want to...
|
by: Mike |
last post by:
Hi
Scenario: I am calling a web method from a WinForms method. The proxy
of the web service then checks one of it's settings.
Depending on the setting I want the proxy to call a method in the...
|
by: shawn |
last post by:
Hi All
Was trying to get this bit of code working (simplified of course)
for (i=0;i<uuid_num;i++) {
window.setInterval(InitMap(uuidValues), timePeriod);
}
Where uuid_num, uuidValues,...
|
by: Earl |
last post by:
I need to call a method on an owned child form, and am wondering if the best
way of doing this is to capture the Closing event of the form that passes
control back to the form where I have the...
| |
by: OneShed |
last post by:
Hi,
I am trying to solve one problem. I have one object and I create another different object from it (aggregation).
How can I now call methods of first object within the second object?
Here is...
|
by: Steve Hershoff |
last post by:
Hi everyone,
We have a javascript function we'd like to call from within a C# method in
our code-behind file. The way it has worked historically is we'd call the
method from a hyperlink, like...
|
by: Andrus |
last post by:
How to call extension method using reflection ?
I tried this code but methodInfo is null.
Andrus.
using System.Reflection;
using System.Windows.Forms;
|
by: =?ISO-8859-1?Q?Fernando_G=F3mez?= |
last post by:
Hello all. I have this class with a virtual method and a constructor
that calls this virtual method. A derived class overrides this virtual
method, so I expected that when the base's constructor is...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |