Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3634762
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:49:10+00:00 2026-05-19T00:49:10+00:00

I have File Like Sample.bak and when I compress it to be Sample.zip I

  • 0

I have File Like “Sample.bak” and when I compress it to be “Sample.zip” I lose the file extension inside the zip file I meann when I open the compressed file I find “Sample” without any extension.

I use this code :

 Dim name As String = Path.GetFileName(filePath).Replace(".Bak", "")
 Dim source() As Byte = System.IO.File.ReadAllBytes(filePath)
 Dim compressed() As Byte = ConvertToByteArray(source)
 System.IO.File.WriteAllBytes(destination & name & ".Bak" & ".zip", compressed)

Or using this code :

Public Sub cmdCompressFile(ByVal FileName As String)

    'Stream object that reads file contents
    Dim streamObj As Stream = New StreamReader(FileName).BaseStream

    'Allocate space in buffer according to the length of the file read
    Dim buffer(streamObj.Length) As Byte

    'Fill buffer
    streamObj.Read(buffer, 0, buffer.Length)
    streamObj.Close()

    'File Stream object used to change the extension of a file
    Dim compFile As System.IO.FileStream = File.Create(Path.ChangeExtension(FileName, "zip"))

    'GZip object that compress the file
    Dim zipStreamObj As New GZipStream(compFile, CompressionMode.Compress)

    'Write to the Stream object from the buffer
    zipStreamObj.Write(buffer, 0, buffer.Length)
    zipStreamObj.Close()

End Sub

please I need to compress the file without loosing file extension inside compressed file.

thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:49:11+00:00Added an answer on May 19, 2026 at 12:49 am

    GZipStream compresses a stream of bytes, it does no more than that. It does not embed file info in the stream, so you need to embed it somewhere.

    The easiest way to restore the file name is to name it with the original name e.g. Sample.bak.zip.

    If that doesn’t work for you can use SharpZipLib (samples here) which does the embedding of the file info for you.

    If you don’t want to go that either of thoes you can either create your own file format and embed the file info or you can try and implement the standard gzip format

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sample file like the following: CREATE GLOBAL TEMPORARY TABLE tt_temp_user_11 (
I have a sample xml file which looks like the one below: <Root> <SubOne>
I have a sample position file like below. 789754654 COLORA SOMETHING1 19370119FYY076 2342423234SS323423 742784897
well i have used an html file like these in iframe <iframe src=sample.html></iframe> is
I have a sample file like this: probeset_id submitted_id chr snp_pos alleleA alleleB 562_201
I have a sample.xml file like this: 'root element 'FilePath element 'FilePath element value
I have a ini file which contains some sample values like: [Section1] Value1 =
I have a file like this called Sample :- 206,,,206,14.9,0,2012/04/24 00:00:05 206,,,206,14.9,0,2012/04/24 00:00:21 205,,,205,14.9,0,2012/04/24
A really simple shell script question. I have a file with something like this:
I have a simple assembly code file called exit.s that looks like the following:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.