上传过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>------------------------------------------------------------
解决方案 »
- asp.net 论坛编辑器
- webservices连接Oracle数据库
- 时间倒计时,怎么不动???
- 调用RunProcedure时(string storedProcName, IDataParameter[] parameters, out int row)
- aspx页面引入jquery的问题
- 关于从数据库读取数据的问题
- 如何实现combobox功能啊???
- 如何实现在DataGrid中鼠标移到某行某列的数据在鼠标下方出现一个小的提示框?
- 求助公文流转系统(Visual 2005 c#)开发!
- using (SqlConnection conn = new SqlConnection())未将对象引用设置到对象的实例怎么解
- 运行时出错!!!
- 关于treeview的问题?bug?
application/octet-stream
不知道正不正确。
另外,文件名需要使用完全名称+扩展名。怎么在input中得到文件的扩展名?
<httpRuntime maxRequestLength="1048576" />
{
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>");
}
站点高级编程上面倒是有存在文件中的方法,用writefile()也不用操心传输类型。
不过我还是想知道怎么从数据库中读出文件来。
http://expert.csdn.net/Expert/TopicView1.asp?id=2513663