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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:35:02+00:00 2026-06-13T02:35:02+00:00

Hi I am Reading a file from the user’s computer then using specific network

  • 0

Hi I am Reading a file from the user’s computer then using specific network credentials to write it out to a network share this corrupts a very small percentage of the files.
when i open the files in a hex editor the hex is different on the first line

Header:    00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
Good File: 50 4b 03 04 14 00 08 00 00 00 37 57 51 41 6f 61
Bad File:  50 4b 03 04 14 00 08 00 00 00 b7 56 51 41 6f 61

The difference in columns 0a and 0b exist throughout the whole file,

If I am going about this the wrong way by all means correct me or if it is just something small that would be better. Any help is much appreciated. The code I am using is below

var fileStream = 
    new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.None);

var impersonationContext =
    new WrapperImpersonationContext("myDomain", "myname", "myPass");

        impersonationContext.Enter();

        try
        {
            using (Stream file = File.OpenWrite(destination))
            {
                fileStream.CopyTo(file);
            }
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }
        finally
        {
            impersonationContext.Leave();

            if(fileStream != null)
            {
                fileStream.Close();
            }
        }
  • 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-06-13T02:35:04+00:00Added an answer on June 13, 2026 at 2:35 am

    FileStream.CopyTo() will write n bytes into the destination file, but won’t erase the end of the destination file that previously existed. Opening the output stream with FileMode.Create should guarantee an exact copy.

    Calling file.SetLength(file.Position); at the end may also work, but I’m not sure how reliably…

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

Sidebar

Related Questions

I'm Using FILE * F opened in _sfopen () I'm reading from the file
Possible Duplicate: reading a specific file from sdcard in android I'm trying to make
I am reading in numbers from a file and then trying to add them
I'm trying to write into an EEPROM via I²C from user space. I'm using
I'm having a problem where instead of reading a text file from the location
I have a HTML file upload field from which I'm reading the file name
I'm trying to call the LumenWorks .csv file reading library from a C++/CLI application
My C/C++ program takes a file from the command line as an argument. Reading
Why does reading from __DATA__ work and reading from the file doesn't (Loose unescaped
I'm trying to convert a string that I'm reading from a file to lowercase

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.