943,736 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 2676
  • ASP.NET RSS
Aug 8th, 2007
0

how letting the user open a file without showing message of (Open,Save,cancel)

Expand Post »
hi all,
i have a list of some files on the server.
i want to let the user choose a file from the list then click a button to open read-only version from this file without showing the popup message that ask user to Open, Save or Cancel.
this is because i don't want to give the user choice to download the file on his local machine.

the used code is as the following:

ASP.NET Syntax (Toggle Plain Text)
  1. private void DownloadFile(string fname)
  2. {
  3. string myPath = Path.GetFullPath(fname);
  4. string name = Path.GetFileName(myPath);
  5. string ext = Path.GetExtension(myPath);
  6. string type = "";
  7. // set known types based on file extension
  8. if (ext != null)
  9. {
  10. switch (ext.ToLower())
  11. {
  12. case ".htm":
  13. case ".html":
  14. type = "text/HTML";
  15. break;
  16.  
  17. case ".txt":
  18. type = "text/plain";
  19. break;
  20.  
  21. case ".doc":
  22. case ".rtf":
  23. type = "Application/msword";
  24. break;
  25.  
  26. case ".xls":
  27. type = "Application/excel";
  28. break;
  29.  
  30. default:
  31. type = "text/plain";
  32. break;
  33. }
  34. }
  35. Response.Buffer = true;
  36. Response.AppendHeader("content-disposition", "attachment; filename=" + name);
  37. //Response.AppendHeader("Pragma","cache");
  38. //Response.AppendHeader("Expires", "-1");
  39. if (type != "")
  40. Response.ContentType = type;
  41.  
  42. Response.WriteFile(myPath);
  43. Response.End();
  44. }

i searched about solve to this issue and i found some advices to change the parameter of the "Response.AppendHeader" function and i tried to follow it as u can see in the commented code but this was not helpful.

i want to solve this problem even the way is through IIS.
any1 has any advices i will be grateful if he/she helped me with it.

thanks for advance.

NAHR ELGANNAH.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
NAHR_ELGANNAH is offline Offline
3 posts
since Aug 2007
Aug 8th, 2007
0

Re: how letting the user open a file without showing message of (Open,Save,cancel)

Remove this is line of code:
Response.AppendHeader("content-disposition", "attachment; filename=" + name);
Regards
Khaled
Reputation Points: 10
Solved Threads: 0
Newbie Poster
atal is offline Offline
24 posts
since Jul 2007
Aug 9th, 2007
0

Re: how letting the user open a file without showing message of (Open,Save,cancel)

thanks Khaled for reply
if i removed this line, it would work fine with some file types (e.g. .doc), but with others e.g.(.txt, .log etc...) it open the file entire the explorer and with other type (e.g. .xls) it prombt the user to Open, Save or Cancel.

if there is solution for this issue, plz send me
and thank you Khaled again
(JAZAK ALLAH KHAIRAN)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
NAHR_ELGANNAH is offline Offline
3 posts
since Aug 2007
Aug 11th, 2007
0

Re: how letting the user open a file without showing message of (Open,Save,cancel)

thanks Khaled for reply
if i removed this line, it would work fine with some file types (e.g. .doc), but with others e.g.(.txt, .log etc...) it open the file entire the explorer and with other type (e.g. .xls) it prombt the user to Open, Save or Cancel.

if there is solution for this issue, plz send me
and thank you Khaled again
(JAZAK ALLAH KHAIRAN)
than why not adding links to your files in place of adding this download code.

Khaled
Reputation Points: 10
Solved Threads: 0
Newbie Poster
atal is offline Offline
24 posts
since Jul 2007
Aug 12th, 2007
0

Re: how letting the user open a file without showing message of (Open,Save,cancel)

Thank you again, Khaled
i tried to do that but the same result is recieved that it works nice with some files but not all.
i really dont know what can i do.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
NAHR_ELGANNAH is offline Offline
3 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Excel macros with asp.net
Next Thread in ASP.NET Forum Timeline: how do I view my home page in IIS?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC