By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,357 Members | 1,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,357 IT Pros & Developers. It's quick & easy.

How to use FolderBrowseDialog control in ASP.NET 2.0

P: n/a
I use VS2005 to build a asp.net 2.0 project. I want to be able to click a
button on the page and have a dialog window appear where I can navigate the
folders to get hold of a file path to load data from the file to a SQL Server
database. I imported System.Data.Forms which gives me access to the
FolderBrowseDialog control. The first problem is that the toolbar did not
show FolderBrowserDialog server control, so I cannot drag it to my form.

Then I try to run the following C# code.

FolderBrowserDialog dial1 = new FolderBrowserDialog();
dial1.ShowDialog();

Then I got a error message.

“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.”

I don’t care it’s a multi threading application. The ideal situation is that
it is a modal dialog to allow me select the file path.

Please help me solving this problem. Thank,
Charts

Jan 16 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
FolderBrowserDialog is a Windows Forms control, you simply cannot expect to
be able to run this in a web page, which is now sitting in the visitors
browser.

For the web, you want the HTMLInputFile control, which provides a button
that opens a local file browse dialog in the browser.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Charts" wrote:
I use VS2005 to build a asp.net 2.0 project. I want to be able to click a
button on the page and have a dialog window appear where I can navigate the
folders to get hold of a file path to load data from the file to a SQL Server
database. I imported System.Data.Forms which gives me access to the
FolderBrowseDialog control. The first problem is that the toolbar did not
show FolderBrowserDialog server control, so I cannot drag it to my form.

Then I try to run the following C# code.

FolderBrowserDialog dial1 = new FolderBrowserDialog();
dial1.ShowDialog();

Then I got a error message.

“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.”

I don’t care it’s a multi threading application. The ideal situation is that
it is a modal dialog to allow me select the file path.

Please help me solving this problem. Thank,
Charts

Jan 16 '06 #2

P: n/a
As Peter adviced you can do something like:-
Sub Upload_Picture_File (Src As Object, Args As EventArgs)

If Not UploadFile.HasFile Then
'-- Missing file selection
Message.Text = "Please choose a file to upload"
Else
If InStr(UCase(UploadFile.FileName), ".JPG") = 0 Then
'-- Selection of non-JPG file
Message.Text = "You can upload only JPG files"
Else
If UploadFile.PostedFile.ContentLength > 100000 Then
'-- File too large
Message.Text = "Uploaded file size must be less than 100 KB"
Else
'-- File upload
UploadFile.SaveAs(Server.MapPath("../Pictures/") &
UploadFile.FileName)
Message.Text = "<b>File Uploaded</b><br/>"
Message.Text &= "File Name: " & UploadFile.FileName & "<br/>"
Message.Text &= "File Size: " & UploadFile.PostedFile.ContentLength
& " bytes<br/>"
End If
End If
End If

End Sub
Hope that helpsPatrick"Peter Bromberg [C# MVP]"
<pb*******@yahoo.nospammin.com> wrote in message
news:8E**********************************@microsof t.com...
FolderBrowserDialog is a Windows Forms control, you simply cannot expect to be able to run this in a web page, which is now sitting in the visitors
browser.

For the web, you want the HTMLInputFile control, which provides a button
that opens a local file browse dialog in the browser.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Charts" wrote:
I use VS2005 to build a asp.net 2.0 project. I want to be able to click a button on the page and have a dialog window appear where I can navigate the folders to get hold of a file path to load data from the file to a SQL Server database. I imported System.Data.Forms which gives me access to the
FolderBrowseDialog control. The first problem is that the toolbar did not show FolderBrowserDialog server control, so I cannot drag it to my form.

Then I try to run the following C# code.

FolderBrowserDialog dial1 = new FolderBrowserDialog();
dial1.ShowDialog();

Then I got a error message.

"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."

I don't care it's a multi threading application. The ideal situation is that it is a modal dialog to allow me select the file path.

Please help me solving this problem. Thank,
Charts

Jan 17 '06 #3

P: n/a
Thanks for all you guys' sharing.

Hi Charts,

As other members have mentioned, file uploading in ASP.NET (or other web
application) are quite different from desktop (winform) application. We
have to use the html file input control to upload file from client. Here
are some additional reference articles which discussing on asp.net file
uploading:

#How to upload a file to a Web server in ASP.NET by using Visual Basic .NET
http://support.microsoft.com/default...b;en-us;323245

#File Upload with ASP.NET
http://www.codeproject.com/aspnet/fileupload.asp

#Uploading Files in ASP.NET 2.0
https://msdn.microsoft.com/asp.net/d...en-us/dnaspp/h
tml/UploadASP2.asp

Hope also helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Patrick.O.Ige" <na********@hotmail.com>
| References: <BA**********************************@microsoft.co m>
<8E**********************************@microsoft.co m>
| Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| Date: Tue, 17 Jan 2006 15:14:05 +1100
| Lines: 86
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
| Message-ID: <O1**************@TK2MSFTNGP15.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 203.36.211.134
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:371315
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| As Peter adviced you can do something like:-
| Sub Upload_Picture_File (Src As Object, Args As EventArgs)
|
| If Not UploadFile.HasFile Then
| '-- Missing file selection
| Message.Text = "Please choose a file to upload"
| Else
| If InStr(UCase(UploadFile.FileName), ".JPG") = 0 Then
| '-- Selection of non-JPG file
| Message.Text = "You can upload only JPG files"
| Else
| If UploadFile.PostedFile.ContentLength > 100000 Then
| '-- File too large
| Message.Text = "Uploaded file size must be less than 100 KB"
| Else
| '-- File upload
| UploadFile.SaveAs(Server.MapPath("../Pictures/") &
| UploadFile.FileName)
| Message.Text = "<b>File Uploaded</b><br/>"
| Message.Text &= "File Name: " & UploadFile.FileName & "<br/>"
| Message.Text &= "File Size: " &
UploadFile.PostedFile.ContentLength
| & " bytes<br/>"
| End If
| End If
| End If
|
| End Sub
| Hope that helpsPatrick"Peter Bromberg [C# MVP]"
| <pb*******@yahoo.nospammin.com> wrote in message
| news:8E**********************************@microsof t.com...
| > FolderBrowserDialog is a Windows Forms control, you simply cannot expect
| to
| > be able to run this in a web page, which is now sitting in the visitors
| > browser.
| >
| > For the web, you want the HTMLInputFile control, which provides a button
| > that opens a local file browse dialog in the browser.
| >
| > Peter
| >
| >
| > --
| > Co-founder, Eggheadcafe.com developer portal:
| > http://www.eggheadcafe.com
| > UnBlog:
| > http://petesbloggerama.blogspot.com
| >
| >
| >
| >
| > "Charts" wrote:
| >
| > > I use VS2005 to build a asp.net 2.0 project. I want to be able to
click
| a
| > > button on the page and have a dialog window appear where I can
navigate
| the
| > > folders to get hold of a file path to load data from the file to a SQL
| Server
| > > database. I imported System.Data.Forms which gives me access to the
| > > FolderBrowseDialog control. The first problem is that the toolbar did
| not
| > > show FolderBrowserDialog server control, so I cannot drag it to my
form.
| > >
| > > Then I try to run the following C# code.
| > >
| > > FolderBrowserDialog dial1 = new FolderBrowserDialog();
| > > dial1.ShowDialog();
| > >
| > > Then I got a error message.
| > >
| > > "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."
| > >
| > > I don't care it's a multi threading application. The ideal situation
is
| that
| > > it is a modal dialog to allow me select the file path.
| > >
| > > Please help me solving this problem. Thank,
| > > Charts
| > >
|
|
|

Jan 17 '06 #4

P: n/a
Thanks guys. I think I’ll use ASP.NET 2.0 FileUpload control. The
FileUpload1.filename (where FileUpload1 is an instance) can return the local
file name. Is there a property can return the whole file path? Thanks!

"Steven Cheng[MSFT]" wrote:
Thanks for all you guys' sharing.

Hi Charts,

As other members have mentioned, file uploading in ASP.NET (or other web
application) are quite different from desktop (winform) application. We
have to use the html file input control to upload file from client. Here
are some additional reference articles which discussing on asp.net file
uploading:

#How to upload a file to a Web server in ASP.NET by using Visual Basic .NET
http://support.microsoft.com/default...b;en-us;323245

#File Upload with ASP.NET
http://www.codeproject.com/aspnet/fileupload.asp

#Uploading Files in ASP.NET 2.0
https://msdn.microsoft.com/asp.net/d...en-us/dnaspp/h
tml/UploadASP2.asp

Hope also helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Patrick.O.Ige" <na********@hotmail.com>
| References: <BA**********************************@microsoft.co m>
<8E**********************************@microsoft.co m>
| Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| Date: Tue, 17 Jan 2006 15:14:05 +1100
| Lines: 86
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
| Message-ID: <O1**************@TK2MSFTNGP15.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 203.36.211.134
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:371315
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| As Peter adviced you can do something like:-
| Sub Upload_Picture_File (Src As Object, Args As EventArgs)
|
| If Not UploadFile.HasFile Then
| '-- Missing file selection
| Message.Text = "Please choose a file to upload"
| Else
| If InStr(UCase(UploadFile.FileName), ".JPG") = 0 Then
| '-- Selection of non-JPG file
| Message.Text = "You can upload only JPG files"
| Else
| If UploadFile.PostedFile.ContentLength > 100000 Then
| '-- File too large
| Message.Text = "Uploaded file size must be less than 100 KB"
| Else
| '-- File upload
| UploadFile.SaveAs(Server.MapPath("../Pictures/") &
| UploadFile.FileName)
| Message.Text = "<b>File Uploaded</b><br/>"
| Message.Text &= "File Name: " & UploadFile.FileName & "<br/>"
| Message.Text &= "File Size: " &
UploadFile.PostedFile.ContentLength
| & " bytes<br/>"
| End If
| End If
| End If
|
| End Sub
| Hope that helpsPatrick"Peter Bromberg [C# MVP]"
| <pb*******@yahoo.nospammin.com> wrote in message
| news:8E**********************************@microsof t.com...
| > FolderBrowserDialog is a Windows Forms control, you simply cannot expect
| to
| > be able to run this in a web page, which is now sitting in the visitors
| > browser.
| >
| > For the web, you want the HTMLInputFile control, which provides a button
| > that opens a local file browse dialog in the browser.
| >
| > Peter
| >
| >
| > --
| > Co-founder, Eggheadcafe.com developer portal:
| > http://www.eggheadcafe.com
| > UnBlog:
| > http://petesbloggerama.blogspot.com
| >
| >
| >
| >
| > "Charts" wrote:
| >
| > > I use VS2005 to build a asp.net 2.0 project. I want to be able to
click
| a
| > > button on the page and have a dialog window appear where I can
navigate
| the
| > > folders to get hold of a file path to load data from the file to a SQL
| Server
| > > database. I imported System.Data.Forms which gives me access to the
| > > FolderBrowseDialog control. The first problem is that the toolbar did
| not
| > > show FolderBrowserDialog server control, so I cannot drag it to my
form.
| > >
| > > Then I try to run the following C# code.
| > >
| > > FolderBrowserDialog dial1 = new FolderBrowserDialog();
| > > dial1.ShowDialog();
| > >
| > > Then I got a error message.
| > >
| > > "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."
| > >
| > > I don't care it's a multi threading application. The ideal situation
is
| that
| > > it is a modal dialog to allow me select the file path.
| > >
| > > Please help me solving this problem. Thank,
| > > Charts
| > >
|
|
|

Jan 17 '06 #5

P: n/a
Hi Charts,

The FileUpload control (actually the <input type="file" ...> html
element)'s file name property just represent the complete filename and path
info on client side. However, I don't think this is useful to you since
your asp.net page's code is running on server side which can not access
clientside's file resource... And when page is being processed at
serverside, the filestream has already been posted, so you can access the
uploaded files' content through serverside code(as mentioned in those
articles)....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Thread-Topic: How to use FolderBrowseDialog control in ASP.NET 2.0
| thread-index: AcYbqzpz2QYNqQAUSwG8j8dkL5bPXA==
| X-WBNR-Posting-Host: 24.173.128.186
| From: =?Utf-8?B?Q2hhcnRz?= <Ac*****@newsgroup.nospam>
| References: <BA**********************************@microsoft.co m>
<8E**********************************@microsoft.co m>
<O1**************@TK2MSFTNGP15.phx.gbl>
<fL*************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| Date: Tue, 17 Jan 2006 13:16:06 -0800
| Lines: 152
| Message-ID: <B5**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 8bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:371548
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks guys. I think I’ll use ASP.NET 2.0 FileUpload control. The
| FileUpload1.filename (where FileUpload1 is an instance) can return the
local
| file name. Is there a property can return the whole file path? Thanks!
|
| "Steven Cheng[MSFT]" wrote:
|
| > Thanks for all you guys' sharing.
| >
| > Hi Charts,
| >
| > As other members have mentioned, file uploading in ASP.NET (or other
web
| > application) are quite different from desktop (winform) application. We
| > have to use the html file input control to upload file from client.
Here
| > are some additional reference articles which discussing on asp.net file
| > uploading:
| >
| > #How to upload a file to a Web server in ASP.NET by using Visual Basic
..NET
| > http://support.microsoft.com/default...b;en-us;323245
| >
| > #File Upload with ASP.NET
| > http://www.codeproject.com/aspnet/fileupload.asp
| >
| > #Uploading Files in ASP.NET 2.0
| >
https://msdn.microsoft.com/asp.net/d...en-us/dnaspp/h
| > tml/UploadASP2.asp
| >
| > Hope also helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| > --------------------
| > | From: "Patrick.O.Ige" <na********@hotmail.com>
| > | References: <BA**********************************@microsoft.co m>
| > <8E**********************************@microsoft.co m>
| > | Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| > | Date: Tue, 17 Jan 2006 15:14:05 +1100
| > | Lines: 86
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
| > | Message-ID: <O1**************@TK2MSFTNGP15.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: 203.36.211.134
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:371315
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | As Peter adviced you can do something like:-
| > | Sub Upload_Picture_File (Src As Object, Args As EventArgs)
| > |
| > | If Not UploadFile.HasFile Then
| > | '-- Missing file selection
| > | Message.Text = "Please choose a file to upload"
| > | Else
| > | If InStr(UCase(UploadFile.FileName), ".JPG") = 0 Then
| > | '-- Selection of non-JPG file
| > | Message.Text = "You can upload only JPG files"
| > | Else
| > | If UploadFile.PostedFile.ContentLength > 100000 Then
| > | '-- File too large
| > | Message.Text = "Uploaded file size must be less than 100 KB"
| > | Else
| > | '-- File upload
| > | UploadFile.SaveAs(Server.MapPath("../Pictures/") &
| > | UploadFile.FileName)
| > | Message.Text = "<b>File Uploaded</b><br/>"
| > | Message.Text &= "File Name: " & UploadFile.FileName & "<br/>"
| > | Message.Text &= "File Size: " &
| > UploadFile.PostedFile.ContentLength
| > | & " bytes<br/>"
| > | End If
| > | End If
| > | End If
| > |
| > | End Sub
| > | Hope that helpsPatrick"Peter Bromberg [C# MVP]"
| > | <pb*******@yahoo.nospammin.com> wrote in message
| > | news:8E**********************************@microsof t.com...
| > | > FolderBrowserDialog is a Windows Forms control, you simply cannot
expect
| > | to
| > | > be able to run this in a web page, which is now sitting in the
visitors
| > | > browser.
| > | >
| > | > For the web, you want the HTMLInputFile control, which provides a
button
| > | > that opens a local file browse dialog in the browser.
| > | >
| > | > Peter
| > | >
| > | >
| > | > --
| > | > Co-founder, Eggheadcafe.com developer portal:
| > | > http://www.eggheadcafe.com
| > | > UnBlog:
| > | > http://petesbloggerama.blogspot.com
| > | >
| > | >
| > | >
| > | >
| > | > "Charts" wrote:
| > | >
| > | > > I use VS2005 to build a asp.net 2.0 project. I want to be able
to
| > click
| > | a
| > | > > button on the page and have a dialog window appear where I can
| > navigate
| > | the
| > | > > folders to get hold of a file path to load data from the file to
a SQL
| > | Server
| > | > > database. I imported System.Data.Forms which gives me access to
the
| > | > > FolderBrowseDialog control. The first problem is that the toolbar
did
| > | not
| > | > > show FolderBrowserDialog server control, so I cannot drag it to
my
| > form.
| > | > >
| > | > > Then I try to run the following C# code.
| > | > >
| > | > > FolderBrowserDialog dial1 = new FolderBrowserDialog();
| > | > > dial1.ShowDialog();
| > | > >
| > | > > Then I got a error message.
| > | > >
| > | > > "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."
| > | > >
| > | > > I don't care it's a multi threading application. The ideal
situation
| > is
| > | that
| > | > > it is a modal dialog to allow me select the file path.
| > | > >
| > | > > Please help me solving this problem. Thank,
| > | > > Charts
| > | > >
| > |
| > |
| > |
| >
| >
|

Jan 18 '06 #6

P: n/a
Hi Steven,
Hi Steven,
Actually, client site file path will help me. When you click the Browse
button for fileupload control and select a file, that file path show up in
the fileupload text box. Do you know any property of fileupload, which can
return that path. The filename property only return the file name. If you add
a fileupload to a page in VS2005, you will see what I meant. The fileupload
control is covered by the article, Uploading Files in ASP.NET 2.0, which you
recommended to me.
Thanks,
Charts

"Steven Cheng[MSFT]" wrote:
Hi Charts,

The FileUpload control (actually the <input type="file" ...> html
element)'s file name property just represent the complete filename and path
info on client side. However, I don't think this is useful to you since
your asp.net page's code is running on server side which can not access
clientside's file resource... And when page is being processed at
serverside, the filestream has already been posted, so you can access the
uploaded files' content through serverside code(as mentioned in those
articles)....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Thread-Topic: How to use FolderBrowseDialog control in ASP.NET 2.0
| thread-index: AcYbqzpz2QYNqQAUSwG8j8dkL5bPXA==
| X-WBNR-Posting-Host: 24.173.128.186
| From: =?Utf-8?B?Q2hhcnRz?= <Ac*****@newsgroup.nospam>
| References: <BA**********************************@microsoft.co m>
<8E**********************************@microsoft.co m>
<O1**************@TK2MSFTNGP15.phx.gbl>
<fL*************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| Date: Tue, 17 Jan 2006 13:16:06 -0800
| Lines: 152
| Message-ID: <B5**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 8bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:371548
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks guys. I think I’ll use ASP.NET 2.0 FileUpload control. The
| FileUpload1.filename (where FileUpload1 is an instance) can return the
local
| file name. Is there a property can return the whole file path? Thanks!
|
| "Steven Cheng[MSFT]" wrote:
|
| > Thanks for all you guys' sharing.
| >
| > Hi Charts,
| >
| > As other members have mentioned, file uploading in ASP.NET (or other
web
| > application) are quite different from desktop (winform) application. We
| > have to use the html file input control to upload file from client.
Here
| > are some additional reference articles which discussing on asp.net file
| > uploading:
| >
| > #How to upload a file to a Web server in ASP.NET by using Visual Basic
.NET
| > http://support.microsoft.com/default...b;en-us;323245
| >
| > #File Upload with ASP.NET
| > http://www.codeproject.com/aspnet/fileupload.asp
| >
| > #Uploading Files in ASP.NET 2.0
| >
https://msdn.microsoft.com/asp.net/d...en-us/dnaspp/h
| > tml/UploadASP2.asp
| >
| > Hope also helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| > --------------------
| > | From: "Patrick.O.Ige" <na********@hotmail.com>
| > | References: <BA**********************************@microsoft.co m>
| > <8E**********************************@microsoft.co m>
| > | Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| > | Date: Tue, 17 Jan 2006 15:14:05 +1100
| > | Lines: 86
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
| > | Message-ID: <O1**************@TK2MSFTNGP15.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: 203.36.211.134
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:371315
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | As Peter adviced you can do something like:-
| > | Sub Upload_Picture_File (Src As Object, Args As EventArgs)
| > |
| > | If Not UploadFile.HasFile Then
| > | '-- Missing file selection
| > | Message.Text = "Please choose a file to upload"
| > | Else
| > | If InStr(UCase(UploadFile.FileName), ".JPG") = 0 Then
| > | '-- Selection of non-JPG file
| > | Message.Text = "You can upload only JPG files"
| > | Else
| > | If UploadFile.PostedFile.ContentLength > 100000 Then
| > | '-- File too large
| > | Message.Text = "Uploaded file size must be less than 100 KB"
| > | Else
| > | '-- File upload
| > | UploadFile.SaveAs(Server.MapPath("../Pictures/") &
| > | UploadFile.FileName)
| > | Message.Text = "<b>File Uploaded</b><br/>"
| > | Message.Text &= "File Name: " & UploadFile.FileName & "<br/>"
| > | Message.Text &= "File Size: " &
| > UploadFile.PostedFile.ContentLength
| > | & " bytes<br/>"
| > | End If
| > | End If
| > | End If
| > |
| > | End Sub
| > | Hope that helpsPatrick"Peter Bromberg [C# MVP]"
| > | <pb*******@yahoo.nospammin.com> wrote in message
| > | news:8E**********************************@microsof t.com...
| > | > FolderBrowserDialog is a Windows Forms control, you simply cannot
expect
| > | to
| > | > be able to run this in a web page, which is now sitting in the
visitors
| > | > browser.
| > | >
| > | > For the web, you want the HTMLInputFile control, which provides a
button
| > | > that opens a local file browse dialog in the browser.
| > | >
| > | > Peter
| > | >
| > | >
| > | > --
| > | > Co-founder, Eggheadcafe.com developer portal:
| > | > http://www.eggheadcafe.com
| > | > UnBlog:
| > | > http://petesbloggerama.blogspot.com
| > | >
| > | >
| > | >
| > | >
| > | > "Charts" wrote:
| > | >
| > | > > I use VS2005 to build a asp.net 2.0 project. I want to be able
to
| > click
| > | a
| > | > > button on the page and have a dialog window appear where I can
| > navigate
| > | the
| > | > > folders to get hold of a file path to load data from the file to
a SQL
| > | Server
| > | > > database. I imported System.Data.Forms which gives me access to
the
| > | > > FolderBrowseDialog control. The first problem is that the toolbar
did
| > | not
| > | > > show FolderBrowserDialog server control, so I cannot drag it to
my
| > form.
| > | > >
| > | > > Then I try to run the following C# code.
| > | > >
| > | > > FolderBrowserDialog dial1 = new FolderBrowserDialog();
| > | > > dial1.ShowDialog();
| > | > >
| > | > > Then I got a error message.
| > | > >
| > | > > "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."
| > | > >
| > | > > I don't care it's a multi threading application. The ideal
situation
| > is
| > | that
| > | > > it is a modal dialog to allow me select the file path.
| > | > >
| > | > > Please help me solving this problem. Thank,
| > | > > Charts
| > | > >
| > |
| > |
| > |
| >
| >
|

Jan 18 '06 #7

P: n/a
Hi Charts,

The ASP.NET 2.0 FileUPload control just encapsulate the <input type="file"
...> element. And you still can access the full file path through it's
PostedFile property. e.g:

protected void btnUpload_Click(object sender, EventArgs e)
{
Response.Write("<br/>FileName: " + FileUpload1.FileName);
Response.Write("<br>FullPath: " + FileUpload1.PostedFile.FileName);

}
Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------
| Thread-Topic: How to use FolderBrowseDialog control in ASP.NET 2.0
| thread-index: AcYcQ4C77rQPf6MxSDSNFkj0rIWJrg==
| X-WBNR-Posting-Host: 24.173.128.186
| From: =?Utf-8?B?Q2hhcnRz?= <Ac*****@newsgroup.nospam>
| References: <BA**********************************@microsoft.co m>
<8E**********************************@microsoft.co m>
<O1**************@TK2MSFTNGP15.phx.gbl>
<fL*************@TK2MSFTNGXA02.phx.gbl>
<B5**********************************@microsoft.co m>
<x4*************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| Date: Wed, 18 Jan 2006 07:26:07 -0800
| Lines: 235
| Message-ID: <23**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 8bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:371754
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi Steven,
| Hi Steven,
| Actually, client site file path will help me. When you click the Browse
| button for fileupload control and select a file, that file path show up
in
| the fileupload text box. Do you know any property of fileupload, which
can
| return that path. The filename property only return the file name. If you
add
| a fileupload to a page in VS2005, you will see what I meant. The
fileupload
| control is covered by the article, Uploading Files in ASP.NET 2.0, which
you
| recommended to me.
| Thanks,
| Charts
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Charts,
| >
| > The FileUpload control (actually the <input type="file" ...> html
| > element)'s file name property just represent the complete filename and
path
| > info on client side. However, I don't think this is useful to you since
| > your asp.net page's code is running on server side which can not access
| > clientside's file resource... And when page is being processed at
| > serverside, the filestream has already been posted, so you can access
the
| > uploaded files' content through serverside code(as mentioned in those
| > articles)....
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | Thread-Topic: How to use FolderBrowseDialog control in ASP.NET 2.0
| > | thread-index: AcYbqzpz2QYNqQAUSwG8j8dkL5bPXA==
| > | X-WBNR-Posting-Host: 24.173.128.186
| > | From: =?Utf-8?B?Q2hhcnRz?= <Ac*****@newsgroup.nospam>
| > | References: <BA**********************************@microsoft.co m>
| > <8E**********************************@microsoft.co m>
| > <O1**************@TK2MSFTNGP15.phx.gbl>
| > <fL*************@TK2MSFTNGXA02.phx.gbl>
| > | Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| > | Date: Tue, 17 Jan 2006 13:16:06 -0800
| > | Lines: 152
| > | Message-ID: <B5**********************************@microsoft.co m>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 8bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:371548
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Thanks guys. I think I’ll use ASP.NET 2.0 FileUpload control.
The
| > | FileUpload1.filename (where FileUpload1 is an instance) can return
the
| > local
| > | file name. Is there a property can return the whole file path?
Thanks!
| > |
| > | "Steven Cheng[MSFT]" wrote:
| > |
| > | > Thanks for all you guys' sharing.
| > | >
| > | > Hi Charts,
| > | >
| > | > As other members have mentioned, file uploading in ASP.NET (or
other
| > web
| > | > application) are quite different from desktop (winform)
application. We
| > | > have to use the html file input control to upload file from client.
| > Here
| > | > are some additional reference articles which discussing on asp.net
file
| > | > uploading:
| > | >
| > | > #How to upload a file to a Web server in ASP.NET by using Visual
Basic
| > .NET
| > | > http://support.microsoft.com/default...b;en-us;323245
| > | >
| > | > #File Upload with ASP.NET
| > | > http://www.codeproject.com/aspnet/fileupload.asp
| > | >
| > | > #Uploading Files in ASP.NET 2.0
| > | >
| >
https://msdn.microsoft.com/asp.net/d...en-us/dnaspp/h
| > | > tml/UploadASP2.asp
| > | >
| > | > Hope also helps. Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | >
| > | > --------------------
| > | > | From: "Patrick.O.Ige" <na********@hotmail.com>
| > | > | References: <BA**********************************@microsoft.co m>
| > | > <8E**********************************@microsoft.co m>
| > | > | Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| > | > | Date: Tue, 17 Jan 2006 15:14:05 +1100
| > | > | Lines: 86
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
| > | > | Message-ID: <O1**************@TK2MSFTNGP15.phx.gbl>
| > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | > | NNTP-Posting-Host: 203.36.211.134
| > | > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet:371315
| > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > |
| > | > | As Peter adviced you can do something like:-
| > | > | Sub Upload_Picture_File (Src As Object, Args As EventArgs)
| > | > |
| > | > | If Not UploadFile.HasFile Then
| > | > | '-- Missing file selection
| > | > | Message.Text = "Please choose a file to upload"
| > | > | Else
| > | > | If InStr(UCase(UploadFile.FileName), ".JPG") = 0 Then
| > | > | '-- Selection of non-JPG file
| > | > | Message.Text = "You can upload only JPG files"
| > | > | Else
| > | > | If UploadFile.PostedFile.ContentLength > 100000 Then
| > | > | '-- File too large
| > | > | Message.Text = "Uploaded file size must be less than 100
KB"
| > | > | Else
| > | > | '-- File upload
| > | > | UploadFile.SaveAs(Server.MapPath("../Pictures/") &
| > | > | UploadFile.FileName)
| > | > | Message.Text = "<b>File Uploaded</b><br/>"
| > | > | Message.Text &= "File Name: " & UploadFile.FileName &
"<br/>"
| > | > | Message.Text &= "File Size: " &
| > | > UploadFile.PostedFile.ContentLength
| > | > | & " bytes<br/>"
| > | > | End If
| > | > | End If
| > | > | End If
| > | > |
| > | > | End Sub
| > | > | Hope that helpsPatrick"Peter Bromberg [C# MVP]"
| > | > | <pb*******@yahoo.nospammin.com> wrote in message
| > | > | news:8E**********************************@microsof t.com...
| > | > | > FolderBrowserDialog is a Windows Forms control, you simply
cannot
| > expect
| > | > | to
| > | > | > be able to run this in a web page, which is now sitting in the
| > visitors
| > | > | > browser.
| > | > | >
| > | > | > For the web, you want the HTMLInputFile control, which provides
a
| > button
| > | > | > that opens a local file browse dialog in the browser.
| > | > | >
| > | > | > Peter
| > | > | >
| > | > | >
| > | > | > --
| > | > | > Co-founder, Eggheadcafe.com developer portal:
| > | > | > http://www.eggheadcafe.com
| > | > | > UnBlog:
| > | > | > http://petesbloggerama.blogspot.com
| > | > | >
| > | > | >
| > | > | >
| > | > | >
| > | > | > "Charts" wrote:
| > | > | >
| > | > | > > I use VS2005 to build a asp.net 2.0 project. I want to be
able
| > to
| > | > click
| > | > | a
| > | > | > > button on the page and have a dialog window appear where I
can
| > | > navigate
| > | > | the
| > | > | > > folders to get hold of a file path to load data from the file
to
| > a SQL
| > | > | Server
| > | > | > > database. I imported System.Data.Forms which gives me access
to
| > the
| > | > | > > FolderBrowseDialog control. The first problem is that the
toolbar
| > did
| > | > | not
| > | > | > > show FolderBrowserDialog server control, so I cannot drag it
to
| > my
| > | > form.
| > | > | > >
| > | > | > > Then I try to run the following C# code.
| > | > | > >
| > | > | > > FolderBrowserDialog dial1 = new FolderBrowserDialog();
| > | > | > > dial1.ShowDialog();
| > | > | > >
| > | > | > > Then I got a error message.
| > | > | > >
| > | > | > > "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."
| > | > | > >
| > | > | > > I don't care it's a multi threading application. The ideal
| > situation
| > | > is
| > | > | that
| > | > | > > it is a modal dialog to allow me select the file path.
| > | > | > >
| > | > | > > Please help me solving this problem. Thank,
| > | > | > > Charts
| > | > | > >
| > | > |
| > | > |
| > | > |
| > | >
| > | >
| > |
| >
| >
|

Jan 19 '06 #8

P: n/a
Yes, it works! Thanks a lot Steven. Charts

"Steven Cheng[MSFT]" wrote:
Hi Charts,

The ASP.NET 2.0 FileUPload control just encapsulate the <input type="file"
...> element. And you still can access the full file path through it's
PostedFile property. e.g:

protected void btnUpload_Click(object sender, EventArgs e)
{
Response.Write("<br/>FileName: " + FileUpload1.FileName);
Response.Write("<br>FullPath: " + FileUpload1.PostedFile.FileName);

}
Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------
| Thread-Topic: How to use FolderBrowseDialog control in ASP.NET 2.0
| thread-index: AcYcQ4C77rQPf6MxSDSNFkj0rIWJrg==
| X-WBNR-Posting-Host: 24.173.128.186
| From: =?Utf-8?B?Q2hhcnRz?= <Ac*****@newsgroup.nospam>
| References: <BA**********************************@microsoft.co m>
<8E**********************************@microsoft.co m>
<O1**************@TK2MSFTNGP15.phx.gbl>
<fL*************@TK2MSFTNGXA02.phx.gbl>
<B5**********************************@microsoft.co m>
<x4*************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| Date: Wed, 18 Jan 2006 07:26:07 -0800
| Lines: 235
| Message-ID: <23**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 8bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:371754
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi Steven,
| Hi Steven,
| Actually, client site file path will help me. When you click the Browse
| button for fileupload control and select a file, that file path show up
in
| the fileupload text box. Do you know any property of fileupload, which
can
| return that path. The filename property only return the file name. If you
add
| a fileupload to a page in VS2005, you will see what I meant. The
fileupload
| control is covered by the article, Uploading Files in ASP.NET 2.0, which
you
| recommended to me.
| Thanks,
| Charts
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Charts,
| >
| > The FileUpload control (actually the <input type="file" ...> html
| > element)'s file name property just represent the complete filename and
path
| > info on client side. However, I don't think this is useful to you since
| > your asp.net page's code is running on server side which can not access
| > clientside's file resource... And when page is being processed at
| > serverside, the filestream has already been posted, so you can access
the
| > uploaded files' content through serverside code(as mentioned in those
| > articles)....
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | Thread-Topic: How to use FolderBrowseDialog control in ASP.NET 2.0
| > | thread-index: AcYbqzpz2QYNqQAUSwG8j8dkL5bPXA==
| > | X-WBNR-Posting-Host: 24.173.128.186
| > | From: =?Utf-8?B?Q2hhcnRz?= <Ac*****@newsgroup.nospam>
| > | References: <BA**********************************@microsoft.co m>
| > <8E**********************************@microsoft.co m>
| > <O1**************@TK2MSFTNGP15.phx.gbl>
| > <fL*************@TK2MSFTNGXA02.phx.gbl>
| > | Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| > | Date: Tue, 17 Jan 2006 13:16:06 -0800
| > | Lines: 152
| > | Message-ID: <B5**********************************@microsoft.co m>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 8bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:371548
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Thanks guys. I think I’ll use ASP.NET 2.0 FileUpload control.
The
| > | FileUpload1.filename (where FileUpload1 is an instance) can return
the
| > local
| > | file name. Is there a property can return the whole file path?
Thanks!
| > |
| > | "Steven Cheng[MSFT]" wrote:
| > |
| > | > Thanks for all you guys' sharing.
| > | >
| > | > Hi Charts,
| > | >
| > | > As other members have mentioned, file uploading in ASP.NET (or
other
| > web
| > | > application) are quite different from desktop (winform)
application. We
| > | > have to use the html file input control to upload file from client.
| > Here
| > | > are some additional reference articles which discussing on asp.net
file
| > | > uploading:
| > | >
| > | > #How to upload a file to a Web server in ASP.NET by using Visual
Basic
| > .NET
| > | > http://support.microsoft.com/default...b;en-us;323245
| > | >
| > | > #File Upload with ASP.NET
| > | > http://www.codeproject.com/aspnet/fileupload.asp
| > | >
| > | > #Uploading Files in ASP.NET 2.0
| > | >
| >
https://msdn.microsoft.com/asp.net/d...en-us/dnaspp/h
| > | > tml/UploadASP2.asp
| > | >
| > | > Hope also helps. Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | >
| > | > --------------------
| > | > | From: "Patrick.O.Ige" <na********@hotmail.com>
| > | > | References: <BA**********************************@microsoft.co m>
| > | > <8E**********************************@microsoft.co m>
| > | > | Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| > | > | Date: Tue, 17 Jan 2006 15:14:05 +1100
| > | > | Lines: 86
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
| > | > | Message-ID: <O1**************@TK2MSFTNGP15.phx.gbl>
| > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | > | NNTP-Posting-Host: 203.36.211.134
| > | > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet:371315
| > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > |
| > | > | As Peter adviced you can do something like:-
| > | > | Sub Upload_Picture_File (Src As Object, Args As EventArgs)
| > | > |
| > | > | If Not UploadFile.HasFile Then
| > | > | '-- Missing file selection
| > | > | Message.Text = "Please choose a file to upload"
| > | > | Else
| > | > | If InStr(UCase(UploadFile.FileName), ".JPG") = 0 Then
| > | > | '-- Selection of non-JPG file
| > | > | Message.Text = "You can upload only JPG files"
| > | > | Else
| > | > | If UploadFile.PostedFile.ContentLength > 100000 Then
| > | > | '-- File too large
| > | > | Message.Text = "Uploaded file size must be less than 100
KB"
| > | > | Else
| > | > | '-- File upload
| > | > | UploadFile.SaveAs(Server.MapPath("../Pictures/") &
| > | > | UploadFile.FileName)
| > | > | Message.Text = "<b>File Uploaded</b><br/>"
| > | > | Message.Text &= "File Name: " & UploadFile.FileName &
"<br/>"
| > | > | Message.Text &= "File Size: " &
| > | > UploadFile.PostedFile.ContentLength
| > | > | & " bytes<br/>"
| > | > | End If
| > | > | End If
| > | > | End If
| > | > |
| > | > | End Sub
| > | > | Hope that helpsPatrick"Peter Bromberg [C# MVP]"
| > | > | <pb*******@yahoo.nospammin.com> wrote in message
| > | > | news:8E**********************************@microsof t.com...
| > | > | > FolderBrowserDialog is a Windows Forms control, you simply
cannot
| > expect
| > | > | to
| > | > | > be able to run this in a web page, which is now sitting in the
| > visitors
| > | > | > browser.
| > | > | >
| > | > | > For the web, you want the HTMLInputFile control, which provides
a
| > button
| > | > | > that opens a local file browse dialog in the browser.
| > | > | >
| > | > | > Peter
| > | > | >
| > | > | >
| > | > | > --
| > | > | > Co-founder, Eggheadcafe.com developer portal:
| > | > | > http://www.eggheadcafe.com
| > | > | > UnBlog:
| > | > | > http://petesbloggerama.blogspot.com
| > | > | >
| > | > | >
| > | > | >
| > | > | >
| > | > | > "Charts" wrote:
| > | > | >
| > | > | > > I use VS2005 to build a asp.net 2.0 project. I want to be
able
| > to
| > | > click
| > | > | a
| > | > | > > button on the page and have a dialog window appear where I
can
| > | > navigate
| > | > | the
| > | > | > > folders to get hold of a file path to load data from the file
to
| > a SQL
| > | > | Server
| > | > | > > database. I imported System.Data.Forms which gives me access
to
| > the
| > | > | > > FolderBrowseDialog control. The first problem is that the
toolbar
| > did
| > | > | not
| > | > | > > show FolderBrowserDialog server control, so I cannot drag it
to
| > my
| > | > form.
| > | > | > >
| > | > | > > Then I try to run the following C# code.
| > | > | > >
| > | > | > > FolderBrowserDialog dial1 = new FolderBrowserDialog();
| > | > | > > dial1.ShowDialog();
| > | > | > >
| > | > | > > Then I got a error message.
| > | > | > >
| > | > | > > "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

Jan 19 '06 #9

P: n/a
You're welcome :-)

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: How to use FolderBrowseDialog control in ASP.NET 2.0
| thread-index: AcYdDwhChFgGwDl3TRKoaaFARM4/GQ==
| X-WBNR-Posting-Host: 72.17.231.234
| From: =?Utf-8?B?Q2hhcnRz?= <Ac*****@newsgroup.nospam>
| References: <BA**********************************@microsoft.co m>
<8E**********************************@microsoft.co m>
<O1**************@TK2MSFTNGP15.phx.gbl>
<fL*************@TK2MSFTNGXA02.phx.gbl>
<B5**********************************@microsoft.co m>
<x4*************@TK2MSFTNGXA02.phx.gbl>
<23**********************************@microsoft.co m>
<ST*************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| Date: Thu, 19 Jan 2006 07:43:02 -0800
| Lines: 304
| Message-ID: <78**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 8bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:372111
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Yes, it works! Thanks a lot Steven. Charts
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Charts,
| >
| > The ASP.NET 2.0 FileUPload control just encapsulate the <input
type="file"
| > ...> element. And you still can access the full file path through it's
| > PostedFile property. e.g:
| >
| > protected void btnUpload_Click(object sender, EventArgs e)
| > {
| > Response.Write("<br/>FileName: " + FileUpload1.FileName);
| > Response.Write("<br>FullPath: " +
FileUpload1.PostedFile.FileName);
| >
| > }
| >
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| > --------
| > | Thread-Topic: How to use FolderBrowseDialog control in ASP.NET 2.0
| > | thread-index: AcYcQ4C77rQPf6MxSDSNFkj0rIWJrg==
| > | X-WBNR-Posting-Host: 24.173.128.186
| > | From: =?Utf-8?B?Q2hhcnRz?= <Ac*****@newsgroup.nospam>
| > | References: <BA**********************************@microsoft.co m>
| > <8E**********************************@microsoft.co m>
| > <O1**************@TK2MSFTNGP15.phx.gbl>
| > <fL*************@TK2MSFTNGXA02.phx.gbl>
| > <B5**********************************@microsoft.co m>
| > <x4*************@TK2MSFTNGXA02.phx.gbl>
| > | Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| > | Date: Wed, 18 Jan 2006 07:26:07 -0800
| > | Lines: 235
| > | Message-ID: <23**********************************@microsoft.co m>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 8bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:371754
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Hi Steven,
| > | Hi Steven,
| > | Actually, client site file path will help me. When you click the
Browse
| > | button for fileupload control and select a file, that file path show
up
| > in
| > | the fileupload text box. Do you know any property of fileupload,
which
| > can
| > | return that path. The filename property only return the file name. If
you
| > add
| > | a fileupload to a page in VS2005, you will see what I meant. The
| > fileupload
| > | control is covered by the article, Uploading Files in ASP.NET 2.0,
which
| > you
| > | recommended to me.
| > | Thanks,
| > | Charts
| > |
| > | "Steven Cheng[MSFT]" wrote:
| > |
| > | > Hi Charts,
| > | >
| > | > The FileUpload control (actually the <input type="file" ...> html
| > | > element)'s file name property just represent the complete filename
and
| > path
| > | > info on client side. However, I don't think this is useful to you
since
| > | > your asp.net page's code is running on server side which can not
access
| > | > clientside's file resource... And when page is being processed at
| > | > serverside, the filestream has already been posted, so you can
access
| > the
| > | > uploaded files' content through serverside code(as mentioned in
those
| > | > articles)....
| > | >
| > | > Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | >
| > | >
| > | > --------------------
| > | > | Thread-Topic: How to use FolderBrowseDialog control in ASP.NET 2.0
| > | > | thread-index: AcYbqzpz2QYNqQAUSwG8j8dkL5bPXA==
| > | > | X-WBNR-Posting-Host: 24.173.128.186
| > | > | From: =?Utf-8?B?Q2hhcnRz?= <Ac*****@newsgroup.nospam>
| > | > | References: <BA**********************************@microsoft.co m>
| > | > <8E**********************************@microsoft.co m>
| > | > <O1**************@TK2MSFTNGP15.phx.gbl>
| > | > <fL*************@TK2MSFTNGXA02.phx.gbl>
| > | > | Subject: Re: How to use FolderBrowseDialog control in ASP.NET 2.0
| > | > | Date: Tue, 17 Jan 2006 13:16:06 -0800
| > | > | Lines: 152
| > | > | Message-ID: <B5**********************************@microsoft.co m>
| > | > | MIME-Version: 1.0
| > | > | Content-Type: text/plain;
| > | > | charset="Utf-8"
| > | > | Content-Transfer-Encoding: 8bit
| > | > | X-Newsreader: Microsoft CDO for Windows 2000
| > | > | Content-Class: urn:content-classes:message
| > | > | Importance: normal
| > | > | Priority: normal
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | > | Path:
| > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet:371548
| > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > |
| > | > | Thanks guys. I think I’ll use ASP.NET 2.0
FileUpload control.
| > The
| > | > | FileUpload1.filename (where FileUpload1 is an instance) can
return
| > the
| > | > local
| > | > | file name. Is there a property can return the whole file path?
| > Thanks!
| > | > |
| > | > | "Steven Cheng[MSFT]" wrote:
| > | > |
| > | > | > Thanks for all you guys' sharing.
| > | > | >
| > | > | > Hi Charts,
| > | > | >
| > | > | > As other members have mentioned, file uploading in ASP.NET (or
| > other
| > | > web
| > | > | > application) are quite different from desktop (winform)
| > application. We
| > | > | > have to use the html file input control to upload file from
client.
| > | > Here
| > | > | > are some additional reference articles which discussing on
asp.net
| > file
| > | > | > uploading:
| > | > | >
| > | > | > #How to upload a file to a Web server in ASP.NET by using
Visual
| > Basic
| > | > .NET
| > | > | > http://support.microsoft.com/default...b;en-us;323245
| > | > | >
| > | > | > #File Upload with ASP.NET
| > | > | > http://www.codeproject.com/aspnet/fileupload.asp
| > | > | >
| > | > | > #Uploading Files in ASP.NET 2.0
| > | > | >
| > | >
| >
https://msdn.microsoft.com/asp.net/d...en-us/dnaspp/h
| > | > | > tml/UploadASP2.asp
| > | > | >
| > | > | > Hope also helps. Thanks,
| > | > | >
| > | > | > Steven Cheng
| > | > | > Microsoft Online Support
| > | > | >
| > | > | > Get Secure! www.microsoft.com/security
| > | > | > (This posting is provided "AS IS", with no warranties, and
confers
| > no
| > | > | > rights.)
| > | > | >
| > | > | >
| > | > | > --------------------
| > | > | > | From: "Patrick.O.Ige" <na********@hotmail.com>
| > | > | > | References:
<BA**********************************@microsoft.co m>
| > | > | > <8E**********************************@microsoft.co m>
| > | > | > | Subject: Re: How to use FolderBrowseDialog control in ASP.NET
2.0
| > | > | > | Date: Tue, 17 Jan 2006 15:14:05 +1100
| > | > | > | Lines: 86
| > | > | > | X-Priority: 3
| > | > | > | X-MSMail-Priority: Normal
| > | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
| > | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
| > | > | > | Message-ID: <O1**************@TK2MSFTNGP15.phx.gbl>
| > | > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | > | > | NNTP-Posting-Host: 203.36.211.134
| > | > | > | Path:
| > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| > | > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > | > microsoft.public.dotnet.framework.aspnet:371315
| > | > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > | > |
| > | > | > | As Peter adviced you can do something like:-
| > | > | > | Sub Upload_Picture_File (Src As Object, Args As EventArgs)
| > | > | > |
| > | > | > | If Not UploadFile.HasFile Then
| > | > | > | '-- Missing file selection
| > | > | > | Message.Text = "Please choose a file to upload"
| > | > | > | Else
| > | > | > | If InStr(UCase(UploadFile.FileName), ".JPG") = 0 Then
| > | > | > | '-- Selection of non-JPG file
| > | > | > | Message.Text = "You can upload only JPG files"
| > | > | > | Else
| > | > | > | If UploadFile.PostedFile.ContentLength > 100000 Then
| > | > | > | '-- File too large
| > | > | > | Message.Text = "Uploaded file size must be less than
100
| > KB"
| > | > | > | Else
| > | > | > | '-- File upload
| > | > | > | UploadFile.SaveAs(Server.MapPath("../Pictures/") &
| > | > | > | UploadFile.FileName)
| > | > | > | Message.Text = "<b>File Uploaded</b><br/>"
| > | > | > | Message.Text &= "File Name: " & UploadFile.FileName &
| > "<br/>"
| > | > | > | Message.Text &= "File Size: " &
| > | > | > UploadFile.PostedFile.ContentLength
| > | > | > | & " bytes<br/>"
| > | > | > | End If
| > | > | > | End If
| > | > | > | End If
| > | > | > |
| > | > | > | End Sub
| > | > | > | Hope that helpsPatrick"Peter Bromberg [C# MVP]"
| > | > | > | <pb*******@yahoo.nospammin.com> wrote in message
| > | > | > | news:8E**********************************@microsof t.com...
| > | > | > | > FolderBrowserDialog is a Windows Forms control, you simply
| > cannot
| > | > expect
| > | > | > | to
| > | > | > | > be able to run this in a web page, which is now sitting in
the
| > | > visitors
| > | > | > | > browser.
| > | > | > | >
| > | > | > | > For the web, you want the HTMLInputFile control, which
provides
| > a
| > | > button
| > | > | > | > that opens a local file browse dialog in the browser.
| > | > | > | >
| > | > | > | > Peter
| > | > | > | >
| > | > | > | >
| > | > | > | > --
| > | > | > | > Co-founder, Eggheadcafe.com developer portal:
| > | > | > | > http://www.eggheadcafe.com
| > | > | > | > UnBlog:
| > | > | > | > http://petesbloggerama.blogspot.com
| > | > | > | >
| > | > | > | >
| > | > | > | >
| > | > | > | >
| > | > | > | > "Charts" wrote:
| > | > | > | >
| > | > | > | > > I use VS2005 to build a asp.net 2.0 project. I want to
be
| > able
| > | > to
| > | > | > click
| > | > | > | a
| > | > | > | > > button on the page and have a dialog window appear where
I
| > can
| > | > | > navigate
| > | > | > | the
| > | > | > | > > folders to get hold of a file path to load data from the
file
| > to
| > | > a SQL
| > | > | > | Server
| > | > | > | > > database. I imported System.Data.Forms which gives me
access
| > to
| > | > the
| > | > | > | > > FolderBrowseDialog control. The first problem is that the
| > toolbar
| > | > did
| > | > | > | not
| > | > | > | > > show FolderBrowserDialog server control, so I cannot drag
it
| > to
| > | > my
| > | > | > form.
| > | > | > | > >
| > | > | > | > > Then I try to run the following C# code.
| > | > | > | > >
| > | > | > | > > FolderBrowserDialog dial1 = new
FolderBrowserDialog();
| > | > | > | > > dial1.ShowDialog();
| > | > | > | > >
| > | > | > | > > Then I got a error message.
| > | > | > | > >
| > | > | > | > > "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
|

Jan 20 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.