473,387 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to use FolderBrowseDialog control in ASP.NET 2.0

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
9 2705
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: sonali_reddy123 | last post by:
Hi, I a facing a problem regarding use of a FolderBrowseDialog in VB.NET. If i select a long path name using the browse dialog then I am getting exception when I say ok to use the selected path...
3
by: Yura Tigiev | last post by:
Hello! Is it possible to write (classical windows with My computers, My Desctop, My networks Places end etc ) FolderBrowseDialog without use WinApi? If yes, can you send source code ? Yuri
0
by: Wilfried Mestdagh | last post by:
Hi, How to set FolderBrowseDialog.Location ? I want to position it in the center of the calling form. Is this possible ? -- rgds, Wilfried http://www.mestdagh.biz
2
by: Peter Lykkegaard | last post by:
Hi All I am looking for a FolderBrowseDialog where I can set a "currentfolder" eg if currentfolder is c:\program files\myapp\data\ etc Not just the common standard folder like "my computer",...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
1
by: Andrue Cope | last post by:
Hi, We have a strange problem. We are invoking the FolderBrowseDialog and have found that if we cancel that dialog within a few seconds of it appearing it causes one of our (completely...
1
by: =?utf-8?B?5qKm5Zyo5aSp5rav?= | last post by:
in the .net freamwork2.0, the openfiledialog support FTP, but the FolderBrowseDialog still do not support the FTP . now i want to make the FolderBrowseDialog to support FTP . can you give me some...
0
by: Newbie19 | last post by:
I'm trying to use folderbrowsedialog on an ASP.net web site to search a network folder and subfolders within for xml or .txt docs that contain data on those subfolders. I was wondering the best way...
1
by: alag20 | last post by:
Hi Guys, I am looking to add a few radio button at the bottom of FolderBrowseDialog in .Net. As it is a part of CommonDialog, then it should be easy to customize however I have never done this and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.