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

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 3
Reputation: NAHR_ELGANNAH is an unknown quantity at this point 
Solved Threads: 0
NAHR_ELGANNAH NAHR_ELGANNAH is offline Offline
Newbie Poster

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

 
0
  #1
Aug 8th, 2007
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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 24
Reputation: atal is an unknown quantity at this point 
Solved Threads: 0
atal atal is offline Offline
Newbie Poster

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

 
0
  #2
Aug 8th, 2007
Remove this is line of code:
Response.AppendHeader("content-disposition", "attachment; filename=" + name);
Regards
Khaled
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3
Reputation: NAHR_ELGANNAH is an unknown quantity at this point 
Solved Threads: 0
NAHR_ELGANNAH NAHR_ELGANNAH is offline Offline
Newbie Poster

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

 
0
  #3
Aug 9th, 2007
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)
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 24
Reputation: atal is an unknown quantity at this point 
Solved Threads: 0
atal atal is offline Offline
Newbie Poster

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

 
0
  #4
Aug 11th, 2007
Originally Posted by NAHR_ELGANNAH View Post
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3
Reputation: NAHR_ELGANNAH is an unknown quantity at this point 
Solved Threads: 0
NAHR_ELGANNAH NAHR_ELGANNAH is offline Offline
Newbie Poster

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

 
0
  #5
Aug 12th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC