Heybo Blog

If you look at me when I'm talking, you'll see what I'm saying ... about Tech and .NET discoveries!

My Links

News

Story Categories

Archives

Post Categories

Image Galleries

Login

Blog Stats

Links

Personal Websites

Protecting Documents , Downloading and ASP.NET for ContentType "Microsoft Word"

Recently I have been trying to figure out a simple (?) way to protect files or content. I do not want to hassle with adjusting file permissions programmatically. I was trying to selectively allow users to download MS Word Docs and here is what I have come up with so far.

string sPath = Server.MapPath("file.doc");

Response.ContentType = "application/msword";

Response.WriteFile(sPath);Response.ContentType = "application/msword";

Response.WriteFile(sPath);

This seems to work okay, but I am not aware of all the security applications or concerns. Also, how to programmatically change the file download name... Of course you have to deny permission of the IUSR to the protected file.

posted on Thursday, February 12, 2004 12:35 PM

Feedback

# re: Protecting Documents , Downloading and ASP.NET for ContentType "Microsoft Word" 5/13/2004 9:02 AM Matt

Response.Clear();
Response.ContentType = "application/msword";
Response.AddHeader("content-disposition", "inline; filename=" + documentName);
FileStream downldstrm = new FileStream(sPath, FileMode.Open);
long FileSize = downldstrm.Length;
byte[] buffer = new byte[(int)FileSize];
downldstrm.Read( buffer, 0, (int)FileSize);
downldstrm.Close();
Response.BinaryWrite( buffer );

Title  
Name  
Url
Comments   
Protected by Clearscreen.SharpHIPEnter the code you see: