Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

Webform with "input type=file" for file upload

已查看 3 次
跳至第一个未读帖子

Bill Murray

未读,
2001年10月18日 13:52:002001/10/18
收件人
If I put a HTML "file" input control on a webform, along with a "save"
button webcontrol, and install the IIS posting server, will it work? Anybody
have a complete working example in WebForms? Does the .net framework provide
any other way for file upload?
I basically need to upload a file, and I would prefer the user interface to
be on a webform.
-Bill Murray
bill....@bull.com


Bill Murray

未读,
2001年10月18日 17:33:132001/10/18
收件人
I also should have said that this is on Win2K with IIS 5. Seems there is no
posting acceptor?
Bill Murray wrote in message ...

Michael Giagnocavo

未读,
2001年10月18日 18:08:392001/10/18
收件人
Just set "Runat=Server" and it becomes a full control that lets you access
the filestream then. Oh ya, you'll need your form to have
"enctype=multipart/form-data" or something like that. The control is called
HtmlInputFileControl I think, and the .NET docs on it are great.
-mike

"Bill Murray" <bill....@bull.com> wrote in message
news:eoKav1$VBHA.2040@tkmsftngp05...

Jun Su

未读,
2001年10月18日 22:44:102001/10/18
收件人
Hi,

My name is Jun Su. Thank you for using Microsoft Community Support.

The following is a sample. This example demonstrates how to use the
HtmlInputFile control to create a simple file upload scenario. For this
example to work properly, you need to create a directory called TEMP on
your C: drive.

[Visual Basic]
<html>
<head>

<script language="VB" runat="server">
Sub Button1_Click(Source As Object, e As EventArgs)

If Text1.Value = "" Then
Span1.InnerHtml = "Error: you must enter a file name"
Return
End If

If Not (File1.PostedFile Is Nothing) Then
Try
File1.PostedFile.SaveAs(("c:\temp\" + Text1.Value))
Span1.InnerHtml = "File uploaded successfully to
<b>c:\\temp\\" & _
Text1.Value & "</b> on the Web server"
Catch exc As Exception
Span1.InnerHtml = "Error saving file <b>c:\\temp\\" & _
Text1.Value & "</b><br>" &
exc.ToString()
End Try
End If
End Sub 'Button1_Click
</script>

</head>
<body>

<h3><font face="Verdana">HtmlInputFile Sample</font></h3>

<form enctype="multipart/form-data" runat="server">

Select File to Upload:
<input id="File1"
type="file"
runat="server">

<p>
Save as filename (no path):
<input id="Text1"
type="text"
runat="server">

<p>
<span id=Span1
style="font: 8pt verdana;"
runat="server" />

<p>
<input type=button
id="Button1"
value="Upload"
OnServerClick="Button1_Click"
runat="server">

</form>

</body>
</html>

I hope this helps. If you have any questions, please reply to this post.

Best Regards,

Jun Su
Microsoft Support

---
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. Copy Right, 2001 Microsoft Corporation.
All rights reserved.

--------------------
>From: "Bill Murray" <bill....@bull.com>
>Subject: Webform with "input type=file" for file upload
>Date: Thu, 18 Oct 2001 10:52:00 -0700

Bill Murray

未读,
2001年10月19日 11:26:512001/10/19
收件人
Thx to Michael and Jun for the pointers, I now have the beautiful solution I
was looking for.

I must admit though that it is frustrating to have all this clearly spelled
out in MSDN, but when I search for something like "webform file upload",
there are no results. I searched using various flavors of keywords and never
got anything that pointed me to the htmlinputfile control. It seems like
some people say about the dictionary, you have to know what you are looking
for.....

thx again

-Bill
Jun Su wrote in message ...

Michael Giagnocavo

未读,
2001年10月19日 14:41:352001/10/19
收件人
Here is a hint: Stick to the .NET Framework Class Reference. Navigate it
until you find what you are looking for.

If you know the name, then the Index is great. Use search when you have
100% no clue, and then try as few words as possible (like input file or
type=file or something like that).

-mike

"Bill Murray" <bill....@bull.com> wrote in message

news:OUWBUJLWBHA.1392@tkmsftngp03...

0 个新帖子