• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4267
  • Last Modified:

Open File Dialog in ASP.net c#

Hi,

 I need that any user can click on a button and an open file dialog is displayed showing only files from web solution 'images' repository so I get the name of a file found in that folder

Thanks in advance
0
negreteo
Asked:
negreteo
  • 2
  • 2
1 Solution
 
Joel CoehoornDirector of Information TechnologyCommented:
ASP.Net has to talk through http and the web browser, just like any other web site.  And web site can't open the common open file dialog for the server's file system.  Period.
0
 
negreteoAuthor Commented:
what about using a javascript?
0
 
Joel CoehoornDirector of Information TechnologyCommented:
The only thing you can do is include a an <input type="file" /> tag.  You will have to implement your own page to show the file listing.
0
 
negreteoAuthor Commented:
This code does the works!!!

const string fiName = "fileBrowse";
System.Text.StringBuilder sb = new System.Text.StringBuilder();

sb.Append("<div style='visibility: hidden; width: 0px; height: 0px'>");
sb.Append(string.Format("<input type=file id='{0}' accept='image/gif,image/jpeg'></div>", fiName));
sb.Append("<Script language=JavaScript> function BrowseClick(){");
sb.Append(String.Format("document.forms[0]['{0}'].click();", fiName));
sb.Append(String.Format("document.forms[0]['{0}'].value = document.forms[0]['{1}'].value;", txtIcon.ClientID, fiName));
sb.Append("return false;} </Script>");
 

RegisterClientScriptBlock("scriptKey", sb.ToString());
cmdGo.Attributes.Add("OnClick", "return BrowseClick();");      
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now