|
Worked out great!!!! Thanks for the pointing to the right direction.
|
|
|
|
|
Hi,
can anyone help me to compress and decompress a text file(.txt) using VB.NET.
I tried but i got error msg as "Magic number in GZip header is INCORRECT".
|
|
|
|
|
thiru_5862 wrote: can anyone help me to compress and decompress a text file(.txt) using VB.NET.
I tried but i got error msg as "Magic number in GZip header is INCORRECT".
You tried with what code??
|
|
|
|
|
Hi Dave.. The code which i use to decompress the file is given below.. Am getting the error "Magic number in GZip header is INCORRECT".
dim source_file as string = "c:/Compressed.txt"
dim destination_file as string = "c:/Decompressed.txt"
Dim sourceFile As FileStream = File.OpenRead(source_file)
Dim destinationFile As FileStream = File.Create(destination_file)
destinationFile.Close()
Dim ms As New MemoryStream()
Dim zipStream As New DeflateStream(ms, CompressionMode.Decompress)
Dim decompressedBuffer(3500) As Byte
System.IO.File.WriteAllBytes(destination_file, decompressedBuffer)
'end writing
'Because the uncompressed size of the file is unknown,
'we are imports an arbitrary buffer size.
Dim buffer(4096) As Byte
Dim n As Integer
Using input As New GZipStream(source_file, _
CompressionMode.Decompress, False)
Console.WriteLine("Decompressing {0} to {1}.", source_file.Name, _
destination_file.Name)
n = input.Read(decompressedBuffer, 0, decompressedBuffer.Length)
destination_file.Write(decompressedBuffer, 0, n)
End Using
'Close the files.
source_file.Close()
destination_file.Close()
|
|
|
|
|
|
Sorry Dave.. I gave the old code .. Below u can find the latest code i use. In the below code.. am getting the exception(Magic number in GZip header is INCORRECT) in line
n = input.Read(decompressedBuffer, 0, decompressedBuffer.Length)
'Compressed File path
dim comp_file as string = "c:/compressed.txt"
'File to which decompressed contents has to be written
dim dest_file as string ="c:/decompressed.txt"
Dim sourceFile As FileStream = File.OpenRead(comp_file)
Dim destinationFile As FileStream = File.Create(dest_file)
destinationFile.Close()
Dim ms As New MemoryStream()
Dim zipStream As New DeflateStream(ms, CompressionMode.Decompress)
Dim decompressedBuffer(3500) As Byte
System.IO.File.WriteAllBytes(dest_file, decompressedBuffer)
'end writing
'Because the uncompressed size of the file is unknown,
'we are imports an arbitrary buffer size.
Dim buffer(4096) As Byte
Dim n As Integer
Using input As New GZipStream(sourceFile, _
CompressionMode.Decompress, False)
Console.WriteLine("Decompressing {0} to {1}.", sourceFile.Name,_
destinationFile.Name)
n = input.Read(decompressedBuffer, 0, decompressedBuffer.Length)
destinationFile.Write(decompressedBuffer, 0, n)
End Using
'Close the files.
sourceFile.Close()
destinationFile.Close()
|
|
|
|
|
This is a bit of spaghetti code, it's a little hard to follow. But, from what I can tell, you're trying to decompress a normal text file, which won't work and would explain the error you're getting. We can't really tell because we don't know the contents of "C:\compressed.txt". Also, forward slashes, in Windows, are used to denote command line paramters, not file paths. I suggest getting into the habit of specifying filepath with backslash's, "\".
|
|
|
|
|
Hi.. thanks for suggesstions.. can u suggest any code that i can use to compress and decompress a text file.
|
|
|
|
|
I dont' have any and don't have the time right now to create an example.
You've got the basic building blocks. You just need to examine your code, and especially the documentation on the zip stream classes, and lay out what you need to do, step-by-step. Just work on compressing a text file to another file first. Once that's done, then you can worry about uncompressing it.
|
|
|
|
|
Dave Kreskowiak wrote: bit of spaghetti
Would you like some Parmesan cheese with that, sir?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
To better help you, provide a sample of the code you are using.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Hi Paul.. The code which i use to decompress the file is given below..
dim source_file as string = "c:/Compressed.txt"
dim destination_file as string = "c:/Decompressed.txt"
Dim sourceFile As FileStream = File.OpenRead(source_file)
Dim destinationFile As FileStream = File.Create(destination_file)
destinationFile.Close()
Dim ms As New MemoryStream()
Dim zipStream As New DeflateStream(ms, CompressionMode.Decompress)
Dim decompressedBuffer(3500) As Byte
System.IO.File.WriteAllBytes(destination_file, decompressedBuffer)
'end writing
'Because the uncompressed size of the file is unknown,
'we are imports an arbitrary buffer size.
Dim buffer(4096) As Byte
Dim n As Integer
Using input As New GZipStream(source_file, _
CompressionMode.Decompress, False)
Console.WriteLine("Decompressing {0} to {1}.", source_file.Name, _
destination_file.Name)
n = input.Read(decompressedBuffer, 0, decompressedBuffer.Length)
destination_file.Write(decompressedBuffer, 0, n)
End Using
'Close the files.
source_file.Close()
destination_file.Close()
|
|
|
|
|
source_file should be sourceFile . You cannot have a string where it is requiring a stream. Same thing applies to destination_file and destinationFile . These are not the cause for your exception, but are a cause for your code not to compile.
You might want to have the following:
source_file.Close()
destination_file.Close()
prior to your attempt at decompressing the file and outputting. This will ensure the buffer is getting flushed and the test compressed file has all of its data written.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Sorry Paul.. I gave the old code .. Below u can find the latest code i used.
In the below.. am getting the exception in line
"n = input.Read(decompressedBuffer, 0, decompressedBuffer.Length)"
'Compressed File path
dim comp_file as string = "c:/compressed.txt"
'File to which decompressed contents has to be written
dim dest_file as string ="c:/decompressed.txt"
Dim sourceFile As FileStream = File.OpenRead(comp_file)
Dim destinationFile As FileStream = File.Create(dest_file)
destinationFile.Close()
Dim ms As New MemoryStream()
Dim zipStream As New DeflateStream(ms, CompressionMode.Decompress)
Dim decompressedBuffer(3500) As Byte
System.IO.File.WriteAllBytes(dest_file, decompressedBuffer)
'end writing
'Because the uncompressed size of the file is unknown,
'we are imports an arbitrary buffer size.
Dim buffer(4096) As Byte
Dim n As Integer
Using input As New GZipStream(sourceFile, _
CompressionMode.Decompress, False)
Console.WriteLine("Decompressing {0} to {1}.", sourceFile.Name,_
destinationFile.Name)
n = input.Read(decompressedBuffer, 0, decompressedBuffer.Length)
destinationFile.Write(decompressedBuffer, 0, n)
End Using
'Close the files.
sourceFile.Close()
destinationFile.Close()
|
|
|
|
|
Dear All,
Iam new to c# window application and also for COM.I have a COM component
which is developed in Visual Basic.Now i want to use this component into
my c# window application.How can i register and use.The COM is in the form
of EXE not in the form of DLL.Please help me out on this.
Thanks & Regards
Veeresh
i want to join this group
|
|
|
|
|
Hi,
The SyncFusion technology can help you please search for that.
Thanks a Lot,
Aleem Mohammad
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
RegSvr32 is used to register COM components, but it your case, it may not work. If this is an .EXE COM server, then the ojects it exposes may not be available at all until your start that .EXE. You won't be able to set a reference to that servers exposed classes, so you might end up using late-binding to get at them. This is not a preferrable situation for someone who is only starting out in C# or VB.NET.
BTW, you asked a question about C# in a VB.NET forum...
|
|
|
|
|
veereshIndia wrote: Now i want to use this component into
my c# window application
You'd be better off asking in the C# forum.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
he'd be better off not asking it in FOUR forums though.
Blog link to be reinstated at a later date.
|
|
|
|
|
It would be nice if there was a ban function to punish people who do so. Whether the ban is temp or perm is a toss up, but the penalty factor would be nice.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Yep. His question should generally be in either the C# forum, or .NET Framework forum. Pick JUST one, not loads of them. It cannot really be that hard.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Hi,
If he asks again in any other forum it becomes like duplicate one, either it is C# or VB.Net converting a COM component process is same, instead of asking him to post in another forum, we can just understand his problem and answer him with good answer.
Isnt it a good Idea?
Thanks,
Aleem Mohammad.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
indian143 wrote: we can just understand his problem and answer him with good answer.
Isnt it a good Idea?
... says the one who is asking the same question over and over again.
Btw, people are asking him to post in one forum and not asking the same question in four forums.
-enter abuse of your choice here-
|
|
|
|
|
Hi,
Yep I did it friend but once upon a time, now I am not doing it because I came to know how to behave in this forum. I got much experience in using this forum.
Any way thanks for bringing my mistakes in to my view.
Thanks a Lot,
Aleem Mohammad.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
No, it's not. If you post a question in multiple forums, you can get different answers, which isn't really a good thing. You're taking away a continuity of discussion, where the good answers are weeded out from bad ones, and more detail required of the OP is lost in one discussion, but exists in another, leading to misinformation on one discussion thread.
|
|
|
|
|