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 6833109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:56:21+00:00 2026-05-26T22:56:21+00:00

I wrote the below method to archive files into one file using binary mode:

  • 0

I wrote the below method to archive files into one file using binary mode:

        // Compile archive
        public void CompileArchive(string FilePath, ListView FilesList, Label Status, ProgressBar Progress)
        {
            FileTemplate TempFile = new FileTemplate();
            if (FilesList.Items.Count > 0)
            {
                BinaryWriter Writer = new BinaryWriter(File.Open(FilePath, FileMode.Create), System.Text.Encoding.ASCII);
                Progress.Maximum = FilesList.Items.Count - 1;
                Writer.Write((long)FilesList.Items.Count);
                for (int i = 0; i <= FilesList.Items.Count - 1; i++)
                {
                    TempFile.Name = FilesList.Items[i].SubItems[1].Text;
                    TempFile.Path = "%ARCHIVE%";
                    TempFile.Data = this.ReadFileData(FilesList.Items[i].SubItems[2].Text + "\\" + TempFile.Name);
                    Writer.Write(TempFile.Name);
                    Writer.Write(TempFile.Path);
                    Writer.Write(TempFile.Data);
                    Status.Text = "Status: Writing '" + TempFile.Name + "'";
                    Progress.Value = i;
                }
                Writer.Close();
                Status.Text = "Status: None";
                Progress.Value = 0;
            }
        }

I read files data using ReadFileData which is in the above method method which return a string of data. (StreamReader) Next up I extract my archive. Everything is done great but the data which will being stored in the extraction method doesn’t give me a right data so the extracted files have not right data to show their original functionality.

Extract method:

    // Extract archive
    public void ExtractArchive(string ArchivePath, string ExtractPath, ListView FilesList, Label Status, ProgressBar Progress)
    {
        FileTemplate TempFile = new FileTemplate();
        BinaryReader Reader = new BinaryReader(File.Open(ArchivePath, FileMode.Open), System.Text.Encoding.ASCII);
        long Count = Reader.ReadInt64();
        if (Count > 0)
        {
            Progress.Maximum = (int)Count - 1;
            FilesList.Items.Clear();
            for (int i = 0; i <= Count - 1; i++)
            {
                TempFile.Name = Reader.ReadString();
                TempFile.Path = Reader.ReadString();
                TempFile.Data = Reader.ReadString();
                Status.Text = "Status: Reading '" + TempFile.Name + "'";
                Progress.Value = i;
                if (!Directory.Exists(ExtractPath))
                {
                    Directory.CreateDirectory(ExtractPath);
                }
                BinaryWriter Writer = new BinaryWriter(File.Open(ExtractPath + "\\" + TempFile.Name, FileMode.Create), System.Text.Encoding.ASCII);
                Writer.Write(TempFile.Data);
                Writer.Close();
                string[] ItemArr = new string[] { i.ToString(), TempFile.Name, TempFile.Path };
                ListViewItem ListItem = new ListViewItem(ItemArr);
                FilesList.Items.Add(ListItem);
            }
            Reader.Close();
            Status.Text = "Status: None";
            Progress.Value = 0;
        }
    }

The structure:

struct FileTemplate
        {
            public string Name, Path, Data;
        }

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-26T22:56:22+00:00Added an answer on May 26, 2026 at 10:56 pm

    Consider using byte arrays for write and safe the data.

    Byte array( write )

    Byte[] bytes = File.ReadAllBytes(..);
    // Write it into your stream
    myStream.Write(bytes.Count);
    myStream.Write(bytes, 0, bytes.Count);
    

    Byte array ( read )

    Int32 byteCount = myStream.ReadInt32();
    Byte[] bytes = new Byte[byteCount];
    myStream.Read(bytes, 0, byteCount);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote the following method to determine the max file size: public static long
I wrote a custom ordering LINQ extension method as below but I think it
I have an interface like below public interface FooDAO { public void callA(String x);
I wrote many Async Future Task Calls one below another in my java program.
Below are two simple Cython methods I wrote. In g_cython() method I used additional
I wrote a Multithreaded program in Java given below :- public class Client {
Everything is working fine until I call the saveFile method (shown below) to write
I use the below code to write code to query a web method in
I wrote the code below : 1. MyClass[] origArr=new MyClass[3]; 2. MyClass[] arr1; 3.
Below is my current char* to hex string function. I wrote it as an

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.