Solved

Open File Dialog in ASP.net c#

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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!
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now