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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:29:56+00:00 2026-05-22T15:29:56+00:00

All right guys and gals it’s time for the age old question, how do

  • 0

All right guys and gals it’s time for the age old question, how do you password protect an xml file using C#?
I have acutally created the file in C# as well (not as if that is relevant) and now I need to password protect it so I can email it out to clients, any suggestions guys,

Also I tried putting the xml file into a zip file, using C# and upon doing this the file loses its extension, and it does this with every method I find, so I would really just like to password protect the original file.


I should have been more clear on this, the file loses it’s extension permanetly, when the end user unzips it, it’s no longer an xml file, it’s just a file with a name, no association or any thing

ok changing this a bit, it’s been pointed out a lot that xml doesn’t get password protected because it’s just text, not a problem, so lets change this up how about the ziping of it

    FileStream sourceFile = File.OpenRead(@"C:\sample.xml");
    FileStream destFile = File.Create(@"C:\sample.zip");

    GZipStream compStream = new GZipStream(destFile, CompressionMode.Compress);

    try
    {
        int theByte = sourceFile.ReadByte();
        while (theByte != -1)
        {
            compStream.WriteByte((byte)theByte);
            theByte = sourceFile.ReadByte();
        }
    }
    finally
    {
        compStream.Dispose();
    } 

this code above zips the file, but when the file is unziped by the end user the file loses it’s xml extension and with it it’s file association

ok i have an update i figured out how to keep the file from losing it’s extension, if i change the output file name to sample.xml.zip, the system handles it fine, granted the output file comes out reading just like this, sample.xml.zip, but winzip never bitches about opening it, neither does 7zip so i’m perfectly happy with this, now the password protected thing is something i haven’t figured out yet.

just for reference sake, my new code.

    FileStream sourceFile = File.OpenRead(@"C:\sample.xml");
    FileStream destFile = File.Create(@"C:\sample.xml.zip");

    GZipStream compStream = new GZipStream(destFile, CompressionMode.Compress);

    try
    {
        int theByte = sourceFile.ReadByte();
        while (theByte != -1)
        {
            compStream.WriteByte((byte)theByte);
            theByte = sourceFile.ReadByte();
        }
    }
    finally
    {
        compStream.Dispose();
    } 
  • 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-22T15:29:56+00:00Added an answer on May 22, 2026 at 3:29 pm

    You can’t password protect an XML file the way you can with a Word document. The reason you can place passwords on Word documents is because Word and presumably other programs which can read Word documents support password protection. Nothing prevents a program from completely ignoring the password (unless the file is somehow encrypted using the password as a key generator).

    XML files are simply text files. No password protection is possible without placing them in a password protected container (such as a zip file). When you zip up the XML file, it is placed inside a zip archive with the extension of .zip to indicate that it is a zip file.

    It is then up to the person receiving the zip file provide the correct password in order to decompress the zip file and retrieve the original XML file.

    I don’t believe .NET has any support for managing .zip files. You can use an third-party library like DotNetZip to help you with this.

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

Sidebar

Related Questions

All right real quick question guys. I know that C# Forms have the OnPaint()
All right so I tried using the button set. So fair, I have been
All right, you guys were very helpful with my last question, so I'll try
Right guys, I have been looking all over the internet for a tutorial to
Right guys, all autocomplete plugins and functions that I've found, they only update upon
I'm using the OnIdle-event for some simple animations, and it works all right. The
you all know: right click -> zoom in or out in flash file, well,
Right now all I am using to calculate the size are the files in
Right guys, I have just started getting into Xcode 4, with the intention to
Hey guys, quick question, all I want to do is resize an image to

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.