这是我的后台代码Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO
Partial Class zjc_career_notice_issues
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
If FileUpload1.PostedFile.FileName = "" Then
Me.lb_info.Text = "请选择文件!"
Else
Dim filepath As String = FileUpload1.PostedFile.FileName
Dim filename As String = filepath.Substring(filepath.LastIndexOf("\\") + 1)
Dim serverpath As String = Server.MapPath(".") + "\\upload\\" + filename '这里设置文件的保存路径
Response.Write(serverpath)
FileUpload1.PostedFile.SaveAs(serverpath)
Me.lb_info.Text = "上传成功! "
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
End SubEnd Class
运行以后,提示 C:\inetpub\wwwroot\zjc-career-websys-2009\\upload\\C:\Users\Administrator\Desktop\asp.net文件上传.txt不支持给定路径的格式。 请各位指点一下。
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO
Partial Class zjc_career_notice_issues
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
If FileUpload1.PostedFile.FileName = "" Then
Me.lb_info.Text = "请选择文件!"
Else
Dim filepath As String = FileUpload1.PostedFile.FileName
Dim filename As String = filepath.Substring(filepath.LastIndexOf("\\") + 1)
Dim serverpath As String = Server.MapPath(".") + "\\upload\\" + filename '这里设置文件的保存路径
Response.Write(serverpath)
FileUpload1.PostedFile.SaveAs(serverpath)
Me.lb_info.Text = "上传成功! "
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
End SubEnd Class
运行以后,提示 C:\inetpub\wwwroot\zjc-career-websys-2009\\upload\\C:\Users\Administrator\Desktop\asp.net文件上传.txt不支持给定路径的格式。 请各位指点一下。
解决方案 »
- 什么情况下使用静态的东东?SQLHELP用static好吗?
- 调查: ASP.NET实现翻页功能用什么控件?
- 为什么同一个程序,把他部署在一个网站(A)下,A里有一段这个程序的代码,打开A网站可以运行程序中的内容,而且是正确的,在B网站下也有程序中的这段代码,为什么打开B网站无法运行正确呢
- 怎样让Gridview中的title只显示10个字符
- 如何通过正则表达式或customvalidator验证上传文件的大小
- xmlhttp+asp.net开发聊天室(急急急急急急急…………)
- 看似简单的sql排序问题!.........
- 求以下正则表达式的写法??
- 100分拉~帮我解决这个问题吧~数据插入数据库问题~
- dropdownlist如何改变后即触发
- 如何在页面上直接点击来播放一个flash文件???请教各位大侠
- 求助~~~~~~~~~Gridview动态生成和值的保存
路径不对。
Me.lb_info.Text = "请选择文件!"
Else
Dim serverpath As String = Server.MapPath(".") + "\\upload\\" + FileUpload1.FileName '这里设置文件的保存路径
Response.Write(serverpath)
FileUpload1.PostedFile.SaveAs(serverpath)
Me.lb_info.Text = "上传成功! "
End If FileUpload1.FileName 直接得到文件名(不带路径的)
改为如:
Dim filename As String = System.Guid.NewGuid().ToString("N") + "." + filepath.Substring(filepath.LastIndexOf(".") + 1);
另外Server.MapPath(".") + "\\upload\\" + filename
改为:
Server.MapPath(".") + "\upload\" + filename
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
If !FileUpload1.HasFile Then
Me.lb_info.Text = "请选择文件!"
Else
Dim filepath As String = FileUpload1.PostedFile.FileName
Dim filename As String = Path.GetFileName(filepath)
Dim serverpath As String = "upload/" + filename '这里设置文件的保存路径
Response.Write(serverpath)
FileUpload1.SaveAs(Server.MapPath("~") + "\\" +serverpath)
Me.lb_info.Text = "上传成功! "
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
这个路径存在。下面是我最新改的代码
If FileUpload1.PostedFile.FileName = "" Then
Me.lb_info.Text = "请选择文件!"
Else
Dim filepath As String = FileUpload1.PostedFile.FileName
Dim filename As String = System.Guid.NewGuid().ToString("N") + "." + filepath.Substring(filepath.LastIndexOf(".") + 1)
Dim serverpath As String = Server.MapPath(".") + "\upload\" + filename '这里设置文件的保存路径
'Response.Write(serverpath)
FileUpload1.PostedFile.SaveAs(serverpath)
Me.lb_info.Text = "上传成功! "
End If
运行后,提示最新的结果。
对路径“C:\inetpub\wwwroot\zjc-career-websys-2009\upload\c359a8436e86406d87d9eae65633408a.doc”的访问被拒绝。
1.你的图片那个文件夹是不是“只读”文件
2.你的这个方法是不是被调用多次,而产生“被拒绝访问”
3.这个文件路径必须是服务器路径,否则会报错。。以上请检查,如有问题可随时向我提出,qq 415845188 或msn [email protected]