<%@ Import Namespace="System.IO" %>
<%@ page Language="vb" debug="true" codepage="936"%>
<html><head><title>UpLoadFile_VB.aspx</title>
<script language="vb" runat="server">
Sub UploadFile(sender as object ,E as EventArgs)
if not myFile.PostedFile is Nothing then
dim PicSize as string=myFile.PostedFile.ContentLength.ToString() dim strFileName as string =myFile.PostedFile.FileName.ToString()
dim namei as integer =strFileName.LastIndexOf(".")
dim strNameX as string=strFileName.Substring(namei)
'Set another file name
dim strNewName as string =Request.UserHostAddress.ToString()+DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+strNameX
dim strFileFolder as string =Server.MapPath("..\uploadfile_ok\1\")
dim strNewFilePath as string =strFileFolder+strNewName
myFile.PostedFile.SaveAs(strNewFilePath)
name.Text=strFileName
fname.Text=myFile.PostedFile.FileName
fenc.Text=myFile.PostedFile.ContentType
fsize.Text=myFile.PostedFile.ContentLength.ToString()
name_cc.Text=strNameX
filesaveto.Text=strNewFilePath
newfilename.Text=strNewName
end if
End Sub
</script>
</head>
<body>
<center>
<h3> UpLoad Files By VB_NET_5 </h3>
<form id="uploderform" method="post" action="uploadfile_c_5.aspx" enctype="multipart/form-data" runat="server" >
<table border="1" cellspacing="0" cellpadding="0" >
<tr> <td><h5>Select File</h5></td</tr>
<tr><td>
<input type="file" id="myFile" runat="server" >
</td></tr>
<tr><td>
<input type="button" value="Upload" OnServerClick="UploadFile" runat="server" >
</td></tr>
</table>
</form>
<br>
<br>
<table border="1" cellspacing="0" width="500">
<tr>
<td width="200">Filename:</td>
<td><asp:label id="name" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="name_cc" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="fname" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="filesaveto" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="fenc" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="fsize" runat="server" />
<tr>
<td></td>
<td><asp:label id="newfilename" runat="server" />
</td></tr>
</td></tr>
</table>
</center>
</body>
</html>
<%@ page Language="vb" debug="true" codepage="936"%>
<html><head><title>UpLoadFile_VB.aspx</title>
<script language="vb" runat="server">
Sub UploadFile(sender as object ,E as EventArgs)
if not myFile.PostedFile is Nothing then
dim PicSize as string=myFile.PostedFile.ContentLength.ToString() dim strFileName as string =myFile.PostedFile.FileName.ToString()
dim namei as integer =strFileName.LastIndexOf(".")
dim strNameX as string=strFileName.Substring(namei)
'Set another file name
dim strNewName as string =Request.UserHostAddress.ToString()+DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+strNameX
dim strFileFolder as string =Server.MapPath("..\uploadfile_ok\1\")
dim strNewFilePath as string =strFileFolder+strNewName
myFile.PostedFile.SaveAs(strNewFilePath)
name.Text=strFileName
fname.Text=myFile.PostedFile.FileName
fenc.Text=myFile.PostedFile.ContentType
fsize.Text=myFile.PostedFile.ContentLength.ToString()
name_cc.Text=strNameX
filesaveto.Text=strNewFilePath
newfilename.Text=strNewName
end if
End Sub
</script>
</head>
<body>
<center>
<h3> UpLoad Files By VB_NET_5 </h3>
<form id="uploderform" method="post" action="uploadfile_c_5.aspx" enctype="multipart/form-data" runat="server" >
<table border="1" cellspacing="0" cellpadding="0" >
<tr> <td><h5>Select File</h5></td</tr>
<tr><td>
<input type="file" id="myFile" runat="server" >
</td></tr>
<tr><td>
<input type="button" value="Upload" OnServerClick="UploadFile" runat="server" >
</td></tr>
</table>
</form>
<br>
<br>
<table border="1" cellspacing="0" width="500">
<tr>
<td width="200">Filename:</td>
<td><asp:label id="name" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="name_cc" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="fname" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="filesaveto" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="fenc" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="fsize" runat="server" />
<tr>
<td></td>
<td><asp:label id="newfilename" runat="server" />
</td></tr>
</td></tr>
</table>
</center>
</body>
</html>
解决方案 »
- Sys.WebForms.PageRequestManagerParserErrorException: 无法分析从服务器收到的消息。之所以出现此错误,常见的原
- 请问为什么repeater读取到的值是<%=now()%>,输出到页面的还是这个值呢
- vs.net2008有哪些新特点和功能呢?
- 200分:js写的控件怎么在大部分机器上的ie能显示,而有些机器的ie却不能显示
- 微软学习中心--注册页面--文本框--很特别,很有用,怎么做的?
- 怎样获得字符串中指定位数的字符
- 我的asp.net程序在服务器上不可用
- linkButton click事件不能不执行
- 关于aps.net的一个菜鸟问题(请高手们指点)
- 向思归大哥请教!!
- 关于动态添加多个listBox控件,并且获得每个listBox 的selectindexchange事件
- 教材都搞不定的问题,请各位大虾指教。
dim strFileFolder as string =Server.MapPath("..\uploadfile_ok\1\")
有误,应该是:
dim strFileFolder as string =Server.MapPath("../uploadfile_ok/1/")其次,我问的是Image的Save方法为什么这里会出错。还是不解阿!!!
System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性错误。 at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) at System.Drawing.Image.Save(String filename) at test.WebForm2.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\test\webform2.aspx.cs:line 61
-------
这是什么原因?我先以为权限不够,可将iis里的虚拟目录的“写入”勾上还是不行。
*********************************************************************************确实是权限不够的原因。
我估计你 iis 的虚拟目录指向的文件夹是在 NTFS 格式的硬盘上的。
如 iis 的虚拟目录指向的文件夹名为 LocalHost应该是右击 LocalHost ,在“共亨与安全”属性里选中“安全”选项卡,添加 aspnet 用户,给 aspnet 用户添加全权。