how to use openfiledialog in asp.net

Posted by Gow.Net under ASP.NET on 9/7/2012 | Points: 10 | Views : 6883 | Status : [Member] | Replies : 2
i need without using fileupload control in asp.net upload my file using openfiledialog.
how to use openfiledialog in asp.net?

gowthaman8870226416


Responses

Posted by: Vijay.K on: 9/7/2012 [Member] Starter | Points: 25

Up
0
Down
OpenFileDialog fDialog = new OpenFileDialog();

fDialog.Title = "Open Image Files";

only allows the files with the name or extension only using jpeg and GIF files

fDialog.Filter = "JPEG Files|*.jpeg|GIF Files|*.gif";


To set the Initial Directory property ,means which directory to show when the open file dialog windows opens

fDialog.InitialDirectory = @"C:\";


if the user has clicked the OK button after choosing a file,To display a MessageBox with the path of the file:

if(fDialog.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(fDialog.FileName.ToString());
}

vijay.k

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gow.Net on: 9/7/2012 [Member] Starter | Points: 25

Up
0
Down
hi Vijay thanks for your replay i already applied that code and i got following error
"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process."

gowthaman8870226416

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response