Solved

Open File Dialog in ASP.net c#

Posted on 2008-06-23
4
4,258 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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