File Selection Dialog

  • Thread starter Thread starter marathoner
  • Start date Start date
M

marathoner

How do we invoke the file selection dialog? I would like to do this in C#
in ASP.net. I would like to open a file for reading.

Marathoner
 
To use OpenFileDialog, I need to use the namespace "System.Windows.Forms".
It doesn't allow me to use this namespace in ASP.net. I get the following
error message:

error CS0234: The type or namespace name 'Windows' does not exist in the
namespace 'System' (are you missing an assembly reference?)



Marathoner
 
I know how to upload a file. What I want to know is how to invoke a file
selection dialog box in ASP.net . I want to be able to select a file.

Marathoner
 
marathoner said:
I know how to upload a file. What I want to know is how to invoke a file
selection dialog box in ASP.net . I want to be able to select a file.

When you place the FileUpload control on a page it includes a Browse button
that allows for selection of a file. The FileUpload control doesn't
actually upload anything by itself, you have to add extra controls to the
ASP.net page to do the actual upload and save of the file. If you look at
the rendered HTML all it does is put an input element on the page of type
file:

<input type="file">

As I said, when the user clicks the browse button that is put of the file
input element, it will display the file selection dialog. See
http://www.quirksmode.org/dom/inputfile.html for some ideas on how you can
customize this type of input.
 
With FileUpload, how do we retrieve the full pathname of the file selected?

Marathoner
 
How do we invoke the file selection dialog? I would like to do this in C#
in ASP.net. I would like to open a file for reading.

Marathoner

You need to very clear here. The file to be opened for reading is where
exactly? On the client or on the server?
 
How do we invoke the file selection dialog? I would like to do this in C#
in ASP.net. I would like to open a file for reading.

Marathoner

The FileUpload Control is a fairly useless control for the task you
describe. Unfortunately when i tried to create a wrapper for the
OpenFileDialog (Made a DLL to call it) i got an error that
OpenFileDialog will only run if the Assembly is marked [STAThread] or
something similar. After playing around with this and not being able
to get it working i resorted to creating a custom form (I only wanted
to pick from one directory). It is obvious that the FileUpload calls
the OpenFileDialog but i suspect its internet explorer that calls it
and deals with the events. Does anyone know of a better control than
FileUpload?
 
It would be helpful if you could tell me how to do it either way (client or
server).

Thanks,

Marathoner
 
marathoner said:
With FileUpload, how do we retrieve the full pathname of the file
selected?

Server side you access the .PostedFile.FileName property. Client side in
javascript you read the .value property.
 
Hi

For opening dialog box and open file or whatever u want to do, u can do
with that.
Great thing is that u can also save textbox value(whic is selected from
dialog box)after page roundtrips.

Because if we select files from HTML input(Browse)
HTML Control then after page referesh or roundtrip that will be empty.

<input id="fileUploadInput" style="width: 57px" type="file"
runat="server" onpropertychange="txtInput.value = this.value" />


Server Control
txtInput(textbox)

So in HTML Code u can see i have set the value of input control to
"txtInput.value = this.value"

So now server control will maintain the state and that text box will not
empty after roundtrips of page.
So here we go.....

Nitin Sharma NXS
 
Hi

For opening dialog box and open file or whatever u want to do, u can do
with that.
Great thing is that u can also save textbox value(whic is selected from
dialog box)after page roundtrips.

Because if we select files from HTML input(Browse)
HTML Control then after page referesh or roundtrip that will be empty.

<input id="fileUploadInput" style="width: 57px" type="file"
runat="server" onpropertychange="txtInput.value = this.value" />


Server Control
txtInput(textbox)

So in HTML Code u can see i have set the value of input control to
"txtInput.value = this.value"

So now server control will maintain the state and that text box will not
empty after roundtrips of page.
So here we go.....

Nitin Sharma NXS
 
Hi

For opening dialog box and open file or whatever u want to do, u can do
with that.
Great thing is that u can also save textbox value(whic is selected from
dialog box)after page roundtrips.

Because if we select files from HTML input(Browse)
HTML Control then after page referesh or roundtrip that will be empty.

<input id="fileUploadInput" style="width: 57px" type="file"
runat="server" onpropertychange="txtInput.value = this.value" />


Server Control
txtInput(textbox)

So in HTML Code u can see i have set the value of input control to
"txtInput.value = this.value"

So now server control will maintain the state and that text box will not
empty after roundtrips of page.
So here we go.....

Nitin Sharma NXS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top