trymyWebClient.UploadFile("http://localhost/uploadtest/aa","POST",@"c:\aa.txt");make sure "http://localhost/uploadtest/aa" knows how to handle file upload
解决方案 »
- 后台Request.QueryString接收a标记传过来的值怎样传到js中
- 关于将Media播放器嵌入到aspx页面的问题??
- 关于nbear的 Gateway的方法,谁有详细的资料?
- asp.net 怎么利用ajax把页面<td>值</td> 传入后台 求详细解说流程
- TreeView中的CheckedNodes
- (C#)在.net中写个类来连接access数据库,出现问题?
- 求助:怎么在后台设置html table中的单元格的样式或class?
- 两页面传值问题
- 第一次写求职信,有经验能帮忙看看还要改哪些地方
- 请教!如何在DataGrid和TextBox之间同步数据?谢谢!!!100分
- 在国内搞信息系统,.NET已是死路!
- 水晶报表求救?
iis中将该目录设定为可以写入
看看这样行不行
myWebClient.UploadFile("http://localhost/uploadtest/aa",@"c:\aa.txt");
但上传的文本中开关是这样的
-----------------------8c41f0926681e70
Content-Disposition: form-data; name="file"; filename="bb.txt"
Content-Type: application/octet-stream
下面是正文
最后是
-----------------------8c41f0926681e70
1、需要将服务器端保存文件的目录设置为任何人可以存取。
2、表单的Enctype(编码类型)属性需设定为"multipart/form-data"。
以下是一个例子
请输入文件路径:
<Input type="File" id="FileUp" runat="server"><p>
<asp:Button id="Upload" OnClick="UpLoadFile" Text="Upload" runat="server"/>
</form>
<Div id="FileInfo" Visible="False" runat="server">
文件名称:<asp:Label id="FName" runat="server"/><br>
文件大小:<asp:Label id="FSize" runat="server"/><br>
文件类型:<asp:Label id="FType" runat="server"/><br>
</Div>
</body>
</html>
<script Language="VB" runat="server">
Sub UpLoadFile(Sender As Object,e As EventArgs)
'如果上传的长度为0,表示没有上传成功
If FileUP.PostedFile.ContentLength=0 Then
Fileinfo.Visible=False
Exit Sub
Else
Fileinfo.Visible=True
End if
'显示上传文件的信息
FSize.Text=CStr(FileUp.PostedFile.ContentLength)
FType.Text=FileUp.PostedFile.ContentType
FName.Text=FileUp.PostedFile.FileName
'储存上传的文件
Dim FileSplit() As String=Split(FileUp.PostedFile.Filename,"\")
Dim FileName As String=FileSplit(FileSplit.Length-1)
FileUP.PostedFile.SaveAs(Server.Mappath(".")&"\"&FileName)
End Sub
</script>
希望能解决你的问题!
保存时要用Server.Mappath(".")。