|
Thanks for the reply.
I'm using dbase IV.
|
|
|
|
|
Are you opening the dbase file in "Shared" mode ? Sounds like you are trying to access a resource with exclusive access and it cannot give it to you because someone else already has the resource.
I don't know the details of how to open a dbase file. I'm just talking theory here.
Good Luck.
|
|
|
|
|
Thanks for the reply.
The dbase file is not used in the shared mode.
Its on the server.
The same dbase file is used by another application and when that application is open, my application crashes.
|
|
|
|
|
Shared mode is for more than one concurrent user
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
An application crashing means you didn't take care of error and/or exception handling properly. Make sure you do, and the app will tell you what is wrong.
|
|
|
|
|
By using catch block and killing the running application, I solved this case.
Thanks for all those who replied and gave suggestions.
It help me to find a solution.
code:
Catch exp As Exception
MsgBox("The Database is used by Ariane. Easy ECN will exit Ariane now.")
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("db2krun")
For Each p As Process In pProcess
p.Kill()
Next
|
|
|
|
|
|
The exception is too general, that might hide problems later on. It'd be preferable to loop through the processes, and to exit if "db2krun" is running. Like this;
Dim pProcess() As Processes = System.Diagnostics.Process.GetProcessesByName("db2krun")
If pProcesses.Count > 0 Then
MsgBox("The Database is currently being used by Ariane. Easy ECN will exit now.")
Application.Terminate
End If
Most importantly, this code would cause your application to exit, as opposed to killing the other application. Imagine a grumpy old man, on a day without coffee. I've been typing in this Ariane for what feels like hours, and just when I'm about to hit the "save" button, and some guy kills the application! What's more, some applications refuse to restart if they're killed at the wrong moment.
The nice thing to do, is to refuse to start at all; the user hasn't any unsaved work in your application, it just began initializing.
I are Troll
|
|
|
|
|
I have been tasked to write an VB.Net application with all reports to be written in SSRS. I have never done SSRS so the first questions,
1. How can I print the report straight to printer and not first browser then print. Can this be done?
2. Can you create a PDF file and not first via browser
What would be the easiest and the fastest way to do these reports from VB.NET?
Thanks in advance.
|
|
|
|
|
This blog post[^] is about the closest you're going to get. It references SSRS 2000, but should still work for 2005. The code is in C#, but is easily converted to VB.NET using any of the online conversion tools.
|
|
|
|
|
Hi all
I has an vb.net application taht is developed in vs 2008.
I created a test cretificate in the Signing tab for test purpose.
Now I want to delete that certificate.
How to do that.
Any help will be helpful.
Thanks in advance.
modified on Thursday, November 18, 2010 3:35 AM
|
|
|
|
|
Start -> Run -> certmgr.msc
You'll probably find the certificate in the Personal folder. Delete JUST your code signing certificate. DO NOT DELETE ANY OTHER CERTIFICATES!
|
|
|
|
|
Thanks a lot.
I have deleted the certificate from the personal folder.
But I find the TemporaryKey.pfx file in my project and I also find in the Signing tab in the Sign the ClickOnce manifests the certificated issued is still displayed.
Ho to remove this?
Thanks in advance.
|
|
|
|
|
OK, so clear the checkbox next to "Sign the ClickOnce manifests" and delete the .pfx file from the project.
|
|
|
|
|
I deleted the .pfx file from the project and cleared the checkbox next to the signing.
But find that the inside the text box, the issued by, issued to ,etc ate displayed but disabled.
Once I check the ClickOnce manifests, it is again displayed active.
Will that affect while publishing the application?
Thanks.
|
|
|
|
|
If the checkbox is turned off, it won't be signed anymore, regardless of what's in the greyed out textbox.
|
|
|
|
|
Thanks for the reply.
I understand now.
|
|
|
|
|
I don't know how many times I've googled this and everything I've looked at doesn't give me a clear answer on what to do. I have file that has combined of many files. An example is |.jpeg|.txt|etc| (file). I know you can't delete from a encrypted file when shouldn't be all that hard to decrypt the file. However, my problem is deleting the .txt in the file.
There it will start out |.jpeg|.txt|etc|
but after running some code it will en up as |.jpeg|etc|
I've used fileStream which I've tried deleting from encrypted and decrypted files. Anything good will help.
|
|
|
|
|
Without more information, it's impossible to help you. You have to know what that file format is (office XML, .ZIP, .RAR, ...) that is holding these files. If it's a custom file format, you're going ot have to find a library or SDK that specifically handles it or write your own. But, in order to do that, you MUST know the exact details of what makes up the archive file format. Without that, you're SOL.
|
|
|
|
|
Well... its a custom made format(.fva). All files are encrypted and made into one file. Than when you want to extract from the file, the application will decrypt and extract the file for you. However, the location/position of the data within the file is in an xml but I'm not having any trouble with this part.
However one problem that's been annoying me for about a week is when you encryption small files, its hard to decrypt it(I'll post the code soon).
The second problem is when you delete from the datagridview. Here is the use case:
1. User selects file from datagridview.
2. User presses delete to delete the file.
3. Application deletes the file in the secure archive location.(this is the problem)
4. Application deletes the file from the xml.(not a problem)
5. Application keeps running until user exits out.
Here is the full code below. Please note I've deleted from the problem section because I've been trying things and googling alot lately.
Imports System.Xml
Imports System.Object
Imports System.Security
Imports System.Security.Cryptography
Imports System.IO
Imports System.IO.Compression
Imports Ionic.Zip
Public Class EncryptDecryptForm
Public index As Integer
Private Sub EncryptDecryptFormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
File_DataGridView.Rows.Clear()
Environment.Exit(0)
End Sub
Private Sub Encrypt_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Encrypt_Browse.Click
'The code below will open a dialog bos '
Dim find As OpenFileDialog = New OpenFileDialog()
find.Title = "File Vault application" 'Title of file browser'
find.InitialDirectory = "c:\"
find.AddExtension = True
find.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
find.FilterIndex = 2
find.RestoreDirectory = True
If find.ShowDialog() = Windows.Forms.DialogResult.OK Then
Me.Encrypt_TextBox.Text = find.FileName
End If
End Sub
Private Sub Decrypt_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Decrypt_Browse.Click
'Code below will start the folder browser'
Dim folder As FolderBrowserDialog = New FolderBrowserDialog()
folder.Description = "Select Folder"
folder.RootFolder = Environment.SpecialFolder.MyComputer
If folder.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.Decrypt_TextBox.Text = folder.SelectedPath.ToString
End If
End Sub
Private Sub Encrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Encrypt.Click
encryption()
End Sub
Private Sub reload()
'This functions reloads the datagrid with the new updated information'
'Replaces the format so the application can read it'
Dim xdoc As XmlDocument = New XmlDocument
xdoc.Load("Resources\FileVault.xml")
Dim name As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim count As Integer
For count = 0 To (name.Count - 1)
File_DataGridView.Rows.Add(name.Item(count).InnerText.ToString, name.Item(count).InnerText.ToString)
Next count
File_DataGridView.AutoResizeColumns()
File_DataGridView.AutoResizeRows()
End Sub
Private Sub Decrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Decrypt.Click
decryption()
End Sub
Private Sub EncryptDecryptForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'When the forms load, this sets up the initial columns and what the user can and can not do to them.'
File_DataGridView.Columns.Add("File name", "File name")
File_DataGridView.ColumnHeadersVisible = True
File_DataGridView.ColumnCount = 1
File_DataGridView.AllowUserToResizeColumns = False
File_DataGridView.AllowUserToAddRows = False
File_DataGridView.AllowUserToResizeRows = False
File_DataGridView.AllowUserToOrderColumns = False
File_DataGridView.AllowDrop = False
File_DataGridView.AllowUserToDeleteRows = True
File_DataGridView.AutoGenerateColumns = True
Dim xdoc As XmlDocument = New XmlDocument
xdoc.Load("Resources\FileVault.xml") 'Load Xml file -> declare location here'
Dim name As XmlNodeList = xdoc.GetElementsByTagName("*******") 'Counts these elements'
Dim count As Integer
For count = 0 To (name.Count - 1) 'This for loop fills the data'
File_DataGridView.Rows.Add(name.Item(count).InnerText.ToString, name.Item(count).InnerText.ToString)
Next count
End Sub
'This function creates the encryption key'
Private Function keyencryption(ByVal strPassword As String) As Byte()
'Converting the character to an array and storing the data
Dim chrdata() As Char = strPassword.ToCharArray
'Make is the same length'
Dim Length As Integer = chrdata.GetUpperBound(0)
'starting to hash the data'
Dim bytDataToHash(Length) As Byte
For i As Integer = 0 To chrdata.GetUpperBound(0)
bytDataToHash(i) = CByte(Asc(chrdata(i)))
Next
'Declaring what Hash to use'
Dim SHA512 As New System.Security.Cryptography.SHA512Managed
'Hashing'
Dim Result As Byte() = SHA512.ComputeHash(bytDataToHash)
Dim resIV(31) As Byte
For i As Integer = 0 To 31
resIV(i) = Result(i)
Next
Return resIV
End Function
'Identical function from above except for a few lines
Private Function IVCreation(ByVal strPassword As String) As Byte()
'Converting the character to an array and storing the data
Dim chrdata() As Char = strPassword.ToCharArray
'Make is the same length'
Dim Length As Integer = chrdata.GetUpperBound(0)
'starting to hash the data'
Dim bytDataToHash(Length) As Byte
For i As Integer = 0 To chrdata.GetUpperBound(0)
bytDataToHash(i) = CByte(Asc(chrdata(i)))
Next
'Declaring what Hash to use'
Dim SHA512 As New System.Security.Cryptography.SHA512Managed
'Hashing'
Dim Result As Byte() = SHA512.ComputeHash(bytDataToHash)
Dim resIV(15) As Byte
For i As Integer = 32 To 47
resIV(i - 32) = Result(i)
Next
Return resIV
End Function
Private Function encryption()
'This sub will encrypt the file, xml edits, update the gridview'
'loading the xml document'
Dim xdoc As XmlDocument = New XmlDocument
Dim key As Byte()
Dim IV As Byte()
'The hardcoded password goes here'
'This is a section just in case you want to a password to your encrypted files'
'Right now it uses the hardcoded password'
'If you can expand this if you want'
key = keyencryption(LoginForm.Password_TextBox.Text)
IV = IVCreation(LoginForm.Password_TextBox.Text)
'if there is an error in the application. A error message will be displayed'
Try
'checking to make sure the text box isn't null'
If (Encrypt_TextBox.Text = "") Then
MessageBox.Show("Need to put in a file location")
Else
'Grabing the file name'
Dim locatefilename As String = Me.Encrypt_TextBox.Text
Dim i As Integer = 0
Dim fnPosition As Integer = 0
'locating all the \ in the string'
While locatefilename.IndexOf("\"c, i) <> -1
fnPosition = locatefilename.IndexOf("\"c, i)
i = fnPosition + 1
End While
Dim junk As String
Dim tfile As String
Dim file As String
Dim ext As String
'This should get all the junk that not need for saving files'
'This should capture what you don't need'
junk = locatefilename.Substring(0, fnPosition)
'This should capture the file'
tfile = locatefilename.Substring(fnPosition + 1)
'Zeroing both i and fnPosition'
i = 0
fnPosition = 0
'taking out the extention in the file and saving it to the xml'
While tfile.IndexOf("."c, i) <> -1
fnPosition = tfile.IndexOf("."c, i)
i = fnPosition + 1
End While
'This should get the actually file name'
file = tfile.Substring(0, fnPosition)
'captures the ext (like the txt)'
'Makes the format of the file invisible but only in the xml'
ext = "." & tfile.Substring(fnPosition + 1)
'Checking to make sure there are not duplicate file name'
Dim name As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim cname As Integer
For cname = 0 To (name.Count - 1)
If (file = name.Item(cname).InnerText) Then
MessageBox.Show("Duplicate file name - either delete the file present in safe or rename file")
Return 1
End If
Next
'This is the file being read in'
Dim fileinput As New System.IO.FileStream(Me.Encrypt_TextBox.Text, IO.FileMode.Open, IO.FileAccess.Read)
'specific file output location here
Dim fileoutput As New System.IO.FileStream("*******", IO.FileMode.Open, IO.FileAccess.Write)
Dim start As Integer = fileoutput.Length
'Declaring variables for encryption'
Dim buffer(4096) As Byte 'Holds the bytes for processing
Dim BytesProcessed As Long = 0 'running count for bytes that are processed'
Dim filelength As Long = fileinput.Length 'Length of file coming in'
Dim bytesinblock As Integer 'current bytes in block'
Dim crypto As CryptoStream
'Declaring crypto service provider'
Dim scRijndael As New System.Security.Cryptography.RijndaelManaged
'setting up progress bars
Encrypt_ProgressBar.Value = 0
Encrypt_ProgressBar.Maximum = 100
crypto = New CryptoStream(fileoutput, scRijndael.CreateEncryptor(key, IV), CryptoStreamMode.Write)
While BytesProcessed < filelength
'reading the file'
bytesinblock = fileinput.Read(buffer, 0, 4096)
'writing the file to cryptoStream'
crypto.Write(buffer, 0, bytesinblock)
'updating bytes processed'
BytesProcessed = BytesProcessed + CLng(bytesinblock)
'equation for updating bytes in block'
Encrypt_ProgressBar.Value = CInt((BytesProcessed / filelength) * 100)
End While
Dim filend As Integer = fileoutput.Length
crypto.Close()
fileinput.Close()
fileoutput.Close()
MessageBox.Show("File is done encrypting")
Encrypt_ProgressBar.Step = 0
Encrypt_ProgressBar.Value = 0
Encrypt_TextBox.Text = ""
'End While
'loading the xml file
xdoc.Load("*******")
'variable for adding a new line'
Dim nline As String = Environment.NewLine
'Creating string for xml file with proper formats'
Dim xmlString As String = nline & " <file>" & nline & " <name>" & file & "</name>" & nline & " <location>" & "Safe\" & file & "</location>" & nline & " <ext>" & ext & "</ext>" & nline & " <beginbyte>" & start & "</beginbyte>" & nline & " <endbytes>" & filend & "</endbytes>" & nline & " </file>" & nline
'the following is used to add the element to the xml'
Dim frag As XmlDocumentFragment = xdoc.CreateDocumentFragment
'Adds the xmlstring to the frag'
frag.InnerXml = xmlString
Dim xroot As XmlNode = xdoc.DocumentElement
'the following statements will add on to the file and save the file'
xroot.AppendChild(frag)
xdoc.Save("*******")
'Clearing the datagrid and reloading the new data, to the eye it you will just blink'
File_DataGridView.Hide()
File_DataGridView.Rows.Clear()
'function reloads the updated xml file'
reload()
File_DataGridView.Show()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return 1
End Function
Private Function decryption()
'This is function is the same as encryption with just a few changes'
'loading the xml document'
Dim xdoc As XmlDocument = New XmlDocument
Dim key As Byte()
Dim IV As Byte()
'The hardcoded password goes here'
'This is a section just in case you want to a password to your encrypted files'
key = keyencryption(LoginForm.Password_TextBox.Text)
IV = IVCreation(LoginForm.Password_TextBox.Text)
'if there is an error in the application. A error message will be displayed'
Try
'checking to make sure the text box isn't null'
If (Decrypt_TextBox.Text = "") Then
MessageBox.Show("Need to put in the file location or select file in grid for decryption")
Else
'declaring string for file'
Dim file As String
Dim tfile As String
Dim deleteExt As String
Dim output As String
Dim fnPosition As Integer
Dim i As Integer
'locating the selected file in the gridview'
'loading the xml file
xdoc.Load("*******")
'Declare name for xml node'
Dim name As XmlNodeList = xdoc.GetElementsByTagName("*******")
'file location is now saved
file = name.Item(index).InnerText
'Substring of file. This is will be convering the file back to its normal
tfile = file.Substring(5)
'retrieving the extenstion'
Dim extname As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim replace As String
deleteExt = extname.Item(index).InnerText
'replacing with proper format'
While tfile.IndexOf("."c, i) <> -1
fnPosition = tfile.IndexOf("."c, i)
i = fnPosition + 1
End While
'This should get the actually file name'
replace = (tfile & deleteExt)
'setting the output file with proper format'
output = Decrypt_TextBox.Text & "\" & replace
Dim filebegin As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim filend As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim intStart As Integer = filebegin.Item(index).InnerText
Dim intEnd As Integer = filend.Item(index).InnerText
'This is go into the Safe and retrieve file'
Dim fileinput As New System.IO.FileStream("Safe.fva", IO.FileMode.Open, IO.FileAccess.Read)
'specific file output location wiht proper extension'
Dim fileoutput As New System.IO.FileStream(output, IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
'The next line makes sure that the file is empty'
fileoutput.SetLength(0)
'Declaring variables for encryption'
Dim buffer(4096) As Byte 'Holds the bytes for processing
Dim BytesProcessed As Long = 0 'running count for bytes that are processed'
Dim filelength As Long = intEnd - intStart 'Length of file coming in where intEnd will be greater than intStart'
Dim bytesinblock As Integer 'current bytes in block
Dim crypto As CryptoStream
'Declaring crypto service provider'
Dim scRijndael As New System.Security.Cryptography.RijndaelManaged
'setting up progress bars
Encrypt_ProgressBar.Value = 0
Encrypt_ProgressBar.Maximum = 100
crypto = New CryptoStream(fileoutput, scRijndael.CreateDecryptor(key, IV), CryptoStreamMode.Write)
fileinput.Position = intStart
While BytesProcessed < filelength
'reading the file'h
bytesinblock = fileinput.Read(buffer, 0, 4096)
'writing the file to cryptoStream'
crypto.Write(buffer, 0, bytesinblock)
'updating bytes processed'
BytesProcessed = BytesProcessed + CLng(bytesinblock)
'equation for updating bytes in block'
Decrypt_ProgressBar.Value = CInt((BytesProcessed / filelength) * 100)
End While
If (filelength = 0) Then
bytesinblock = fileinput.Read(buffer, 0, 4096)
crypto.Write(buffer, 0, bytesinblock)
End If
crypto.Close()
fileinput.Close()
fileoutput.Close()
MessageBox.Show("File is done decrypting")
Decrypt_ProgressBar.Step = 0
Decrypt_ProgressBar.Value = 0
Decrypt_TextBox.Text = ""
End If
Catch ex As Exception
MsgBox(ex.StackTrace.ToString)
End Try
Return 1
End Function
Public Sub File_DataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles File_DataGridView.CellClick
index = e.RowIndex
End Sub
Private Sub File_DataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles File_DataGridView.UserDeletingRow
Dim xdoc As XmlDocument = New XmlDocument
xdoc.Load("*******")
Dim filebegin As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim filend As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim intStart As Integer = filebegin.Item(index).InnerText
Dim intEnd As Integer = filend.Item(index).InnerText
Dim deletefile As New System.IO.FileStream("*******", FileMode.Open)
Dim deletethis As Integer = CLng(deletefile.Length)
'Deletes the actual file'
Dim location As XmlNodeList = xdoc.GetElementsByTagName("*******")
Dim del_location As String = location.Item(index).InnerText
'Deletes the information in the xml'
Dim name As XmlNodeList = xdoc.GetElementsByTagName("*******")
name.Item(index).RemoveAll()
name.Item(index).ParentNode.RemoveChild(name.Item(index))
xdoc.Save("********")
End Sub
End Class
All help will be greatly appriecated.
|
|
|
|
|
This has got so many problems I don't know where to start.
First, you've got an XML file that holds all the position data in the archive, but you've got nothing persisting this XML data anywhere. Once you're app is closed, it's gone and you have no hope of decrypting the data in the archive, let alone finding it.
You've got no code at all that removes a file from the archive, nor anything that updates pointers to where the remaining files would now be in the modified archive. You've got nothing to add files, nothing to manage the collection of files and the data, no real data structures tracking this stuff, ... basically, this was done entirely wrong. From what I can see in this code, you've got no hope of fixing this because it has to be completely torn down and a new library created that just handles these custom archive files. Forget the form stuff and getting values from TextBox's. The library shouldn't care at all about TextBox's. It should only get it's data from parameters passed into well crafted methods, such as (an overly simplified list!) AddFile(filepath), DeleteFile(filepath), CreateNewArchive(archivePath), ...
|
|
|
|
|
I don't think I need persists when the application isn't going to be web based. I mean it decrypts fine but my problem is deleting the file from the secure file. I understand about the data Structure but this is a application is form based and I have to do it this way. If it was for me, I prolly would use vb to do this.
|
|
|
|
|
No one said anything about this being web-based.
What you have simply isn't going to work - period, end of story. You have nothing managing the format of the file at all, maintaining the indexes where the start of every file is in the archive, which is a non-optional requirement for functionality like this.
|
|
|
|
|
What will be used to manage the xml? An object? make it object orientated.
|
|
|
|
|
That's where your data structures come in. You can create your own class that tracks this information and is serializable.
In my humble opinion, Version 1 of my file format would lay out like this:
preamble bytes (signature)
64-bit integer offset of file table
encrypted file1 bytes
encrypted file2 bytes
encrypted file3 bytes
encrypted file4 bytes
encrypted file5 bytes
.
.
.
file table data
By putting the file table data at the end of the file, you make it easier to add and remove files from the archive as every time you close the archive, you have to write the file table to the end of the file, at a easily obtainable offset. Once that is written, you can update the fixed length 64-bit integer offset with the beginning of the file table.
Like I said, this would be my version 1 layout. Version 2 would probably add a file header to each file with checksum and length data and maybe a second copy of the file table data for backup purposes. You could even write a tool to recover salvagable files from a corrupted archive if you so choose.
Why WOULDN'T I do this? Because if the archive gets damaged, your archive isn't supported by ANY recovery and analysis tools used on other well-known file formats, unless you write these tools yourself.
|
|
|
|
|