Solved

Open File Dialog in ASP.net c#

Posted on 2008-06-23
4
4,256 Views
Last Modified: 2008-07-01
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
Comment
Question by:negreteo
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 21850894
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
 

Author Comment

by:negreteo
ID: 21851634
what about using a javascript?
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 21851885
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
 

Accepted Solution

by:
negreteo earned 0 total points
ID: 21852006
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question