这是我的后台代码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不支持给定路径的格式。 请各位指点一下。

解决方案 »

  1.   

    “运行以后,提示 C:\inetpub\wwwroot\zjc-career-websys-2009\\upload\\C:\Users\Administrator\Desktop\asp.net文件上传.txt”不支持给定路径的格式。 “
    路径不对。
      

  2.   

                If FileUpload1.PostedFile.FileName = "" Then 
                    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 直接得到文件名(不带路径的)
      

  3.   

     Dim filename As String = filepath.Substring(filepath.LastIndexOf("\\") + 1) 
    改为如:
    Dim filename As String = System.Guid.NewGuid().ToString("N") + "." + filepath.Substring(filepath.LastIndexOf(".") + 1);
    另外Server.MapPath(".") + "\\upload\\" + filename 
    改为:
    Server.MapPath(".") + "\upload\" + filename 
      

  4.   

    asp.net下的文件路径的:获得虚拟目录的网站的根目录
      

  5.   


    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 
      

  6.   

     C:\inetpub\wwwroot\zjc-career-websys-2009\路径是否存在,在虚拟目录里用相对路径。
      

  7.   

    C:\inetpub\wwwroot\zjc-career-websys-2009\
    这个路径存在。下面是我最新改的代码
    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”的访问被拒绝。 
      

  8.   

    我遇到过类似的问题:你检查看看是不是以下问题:
       1.你的图片那个文件夹是不是“只读”文件
       2.你的这个方法是不是被调用多次,而产生“被拒绝访问”
       3.这个文件路径必须是服务器路径,否则会报错。。以上请检查,如有问题可随时向我提出,qq  415845188 或msn [email protected]