trymyWebClient.UploadFile("http://localhost/uploadtest/aa","POST",@"c:\aa.txt");make sure "http://localhost/uploadtest/aa" knows how to handle file upload

解决方案 »

  1.   

    可能是权限问题吧,设定一下你服务器目录uploadtest/aa
    iis中将该目录设定为可以写入
    看看这样行不行
      

  2.   

    what is in your "aa"? try to upload a file from html to make sure your "aa" script works
      

  3.   

    我改成这样就行了
    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
      

  4.   

    上传时要注意的问题:
    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(".")。
      

  5.   

    多谢w18ily(#vb#) ,你这种方法我也成功了。我现在主要想知道为什么我上面那个方法不行。还有一个,如果象你这样好象和服务器端的目录属性无关,因为我可以saveas("c:\aa");我的C不是对作何人都开放的。