0

Is there anyway to read a Open a password protected text file in C# code.

It is not an encrypted file but a password protected text file.

picture showing where its asking for password

svick
  • 236,525
  • 50
  • 385
  • 514
Smitha Kalluz
  • 309
  • 5
  • 10
  • 1
    Could you explain what you mean by "password protected?" As far as I know, Windows doesn't have a concept of password protected files. Do you have some sort of add-in for your OS that does password protection? – Jacob Nov 26 '13 at 01:52
  • I'd be surprised if any Mono-supported OS's have password protection at the FS level as well. – Jacob Nov 26 '13 at 01:57
  • This is how we receive the files from the third party gives us the files. It is windows. – Smitha Kalluz Nov 26 '13 at 01:58
  • Are you maybe talking about the prompt for credentials you get from Windows when accessing a file on a network? If so, see http://stackoverflow.com/questions/15016938/how-to-open-file-by-specific-user. Otherwise, this doesn't sound like a text file, but a file that opens in some application that has password capabilities. How do you open the file manually? – Jacob Nov 26 '13 at 02:00
  • no I actually am not able to attach a pic as i do not have bonus points. I am not asking about shared drive password. It is actually a windows password. I shall try and upload it somewhere else and add a link – Smitha Kalluz Nov 26 '13 at 02:02
  • https://picasaweb.google.com/115996202920892297502/November252013 Check this link for the picture showing where its asking for password – Smitha Kalluz Nov 26 '13 at 02:08
  • No its the text file that is encrypted Not the Zip file – Smitha Kalluz Nov 26 '13 at 02:11
  • Yes it is a Text SP.text is the name of the text file . I have marked off the rest of the file name in black to avoid displaying full filename on internet. And the "..." is just addition to the message box it seems – Smitha Kalluz Nov 26 '13 at 02:14
  • @user1715751 Well, it's the txt file inside the zip archive that's password protected. And that protection is zip-specific. – svick Nov 26 '13 at 02:14
  • Good . I did not find any help online anywhere on password protected text files – Smitha Kalluz Nov 26 '13 at 02:18

1 Answers1

4

I had no trouble reproducing that dialog:

enter image description here

The dialog styling is a little different, this came from a Windows 8.1 machine. But it is the exact same one as yours. It is displayed when you open a .zip archive that's password protected with Windows Explorer. Which displays the prompt when you double-click a file inside the archive.

You extract files from a .zip archive in your own code with one of the many Zip libraries. Popular ones are SharpZiplib, DotNetZip and 7-Zip. They all support extracting files that are password protected, covered by this question.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 1
    It is a poorly documented question, that doesn't make the subject of using a zip library in a .NET program off topic. – Hans Passant Nov 26 '13 at 02:39
  • 3
    The [c#] tag is a pretty good hint. Why are you giving me a hard time answering a difficult question? You can express your displeasure by voting on the question. Get off my case, please. – Hans Passant Nov 26 '13 at 02:42
  • Thanks @hans I shall use the ShareZipLib and yes its .NET application – Smitha Kalluz Nov 26 '13 at 14:50