0

Made an ASP.NET web application which receives a file using file upload control and then encrypts file name on upload.

But when I redirect a user to file_address (so this user can download the file) I don't know how can i decrypt the file name now? because a file (for example a .docx file) doesn't have code behind.

So when the user downloads the file He/She receives a file with encrypted name!

All files in the server have a encrypted name and not their original name And What i want to know is how to give files their original name when users download files

Divyang Desai
  • 7,483
  • 13
  • 50
  • 76
Alex Lee
  • 1
  • 3

1 Answers1

2

You can't give the user a direct link to the file - rather a page that first decrypts the file, then writes appropriate response headers and sends the decrypted file as a response.

Like getFile.aspx?encryptedFileName=abcxyz. In Init, getfile.aspx loads the encrypted file, decrypts it, then writes appropriate response headers for the file, changing MIME type to whatever the file requires, and sending the decrypted file instead of a web page.

Here's an example of how to do this with a ZIP file. If you need more help after looking at this, let me know. How do I generate and send a .zip file to a user in C# ASP.NET?

Community
  • 1
  • 1
Shannon Holsinger
  • 2,293
  • 1
  • 15
  • 21
  • Wait , Does it rename the file on the server in this way or it just downloads the fie with a decrypted name? – Alex Lee Aug 29 '16 at 12:41
  • It could do either, but it wouldn't inherently rename the file on the server that way - you'd have to add that as another step. It'd be like File(@"c:\encryptedfiles\abcdxyz").SendToClientAs("TheFileYouSaved.xlsx"); – Shannon Holsinger Aug 29 '16 at 19:20