Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a fileupload control:
XML
<asp:FileUpload ID="file" runat="server" Width="100%" />

Then I register some javascript in the codebehind:
XML
this.Page.ClientScript.RegisterClientScriptBlock(typeof(string), "file", "<script language=javascript> function BrowseClick() { "
  + "document.getElementById('" + this.file.ClientID.ToString() + "').click(); return false; } </script>");

Then I add the function to the attributes of an ASP.NET button:
C++
this.btnDownload.Attributes.Add("onclick", "BrowseClick");

When I click this button I expect a file dialog to open, but nothing happens. Why?
Also, I want the fileupload to open as a "save as" dialog instead of a "file open" dialog. How can this be done?
Posted
Comments
E.F. Nijboer 21-Jul-10 8:29am    
when you look at the html source in the browser during debugging, what do you see?

I did mention earlier something about "javascript:BrowseClick();", could this apply here?
Hardus Lombaard 21-Jul-10 8:53am    
"javascript:BrowseClick();" works!! Thanks. Now could you please also tell me how to open the fileupload dialog as a "save as" dialog instead of a "file open" dialog? Thanks for all your help.

1 solution

Have a look at this article, sounds like the same thing you need:
File download using C# [^]

It says, for SaveAs dialog in ASP.NET you need to add these to the response header:
Response.ContentType="application/ms-word";
Response.AddHeader( "content-disposition","attachment; filename=download.doc");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900