上传过rar、exe等类型文件!代码如下:
---------------------------------------------------------
        Public Function UploadFile(ByVal FileFieldArg As HtmlControls.HtmlInputFile, ByVal strServerPathFileName As String) As String
            Dim FileMe As System.IO.File
            Dim strReturn As String
            Try
                If FileFieldArg.PostedFile.ContentLength <= 0 Then
                    Return "MSG_FAULT_FILE_1001"
                End If                If FileFieldArg.PostedFile.FileName <> "" Then
                    FileFieldArg.PostedFile.SaveAs(Server.MapPath(strServerPathFileName))
                Else
                    Return "MSG_FAULT_FILE_1001"
                End If                '检查是否正确完成上传
                If FileMe.Exists(Server.MapPath(strServerPathFileName)) = False Then
                    Return "MSG_FAULT_OPER_1001"
                End If
            Catch e As Exception
                Return "MSG_FAULT_OPER_1001"
            End Try            Return "MSG_SUCCESS_OPER_1001"        End Function注意:(1)strServerPathFileName ----路径指服务器的IIS虚拟路径
      (2)使用本函数时,Form对象必须设置成 enctype ="multipart/form-data"
-------------------------------------------------------------文件限量问题,在web.config中增添如下代码:
-------------------------------------------------------------<system.web>
.......<httpRuntime maxRequestLength="1024*1024" useFullyQualifiedRedirectUrl="false" executionTimeout="6000" />.......     
  </system.web>------------------------------------------------------------

解决方案 »

  1.   

    谢谢楼上的仁兄,我可以实现上传但不能正确的从数据库中读出。无法识别文件类型
    application/octet-stream
    不知道正不正确。
    另外,文件名需要使用完全名称+扩展名。怎么在input中得到文件的扩展名?
      

  2.   

    上传任何文件都是一样的,象76wzc(麦田人)给的代码。至于下载,象rar、exe等类型的文件只需要将url链接指向该文件即可。在web.config中 <httpRuntime maxRequestLength="1024*1024" /> 这样的设置是错误的,因为maxRequestLength只能是一个整数值,不能写成一个算式,正式的写法是
    <httpRuntime maxRequestLength="1048576" />
      

  3.   

    if (drupdow.Read())
    {
    Response.ContentType = "application/x-msdownload";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(drupdow.GetString(1).Trim()) + ""+ drupdow["expandname"].ToString().Trim() +"");
    Response.BinaryWrite((byte[])drupdow["side"]);
    Response.Flush();
    Response.End();
    RegisterStartupScript("alert", "<script language='javascript'> alert('附件成功下载!')</script>");
    }
      

  4.   

    这样呀!我考虑一下。
    站点高级编程上面倒是有存在文件中的方法,用writefile()也不用操心传输类型。
    不过我还是想知道怎么从数据库中读出文件来。
      

  5.   

    通用上传(到Sql Server)下载文件--完全代码
    http://expert.csdn.net/Expert/TopicView1.asp?id=2513663