0

In my ASP.Net website I want to upload a file onClickEvent of LinkButton. I dont have a space to show a FileUpload Control. But if we use fileUpload control it is easy to upload a file using:

String filename = Path.GetFileName(FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath("~/files/") + filename);

How do I open file browser on onClick event of LinkButton and save my file inside the Files folder present on the server?

EDIT:
can we use "OpenFileDialog" From Windows.Forms? If yes, how? i am just asking...

Prasad Jadhav
  • 5,090
  • 16
  • 62
  • 80
  • If the issue is just UI real-estate, could you not just have a link that opens a pop-up window or modal window and put the FileUpload control in that? – Neil Thompson Sep 12 '12 at 11:09
  • Yes. At first I thought of this way, but again it will be a headache for user as it involves 2-3 steps to complete a simple action. – Prasad Jadhav Sep 12 '12 at 11:21
  • you could use javascript then? http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery discusses the issue and has links to plugins that might suit your needs – Neil Thompson Sep 12 '12 at 11:28

1 Answers1

0

You can use javascript as suggested by Neil Thompson. However, my preferred solution to this issue is the CSS method as described in this post. You can also use the ASP upload control if you wish, and it will be hidden in the same way, allowing you to handle the file in the code behind as you usually would.

Also, as far as I can tell this works in all popular browsers.

Community
  • 1
  • 1
JDandChips
  • 9,780
  • 3
  • 30
  • 46