未声明“路径"错误.由于其保护级别,它可能无法访问. [英] Error-'Path' is not declared. It may be inaccessible due to its protection level.

查看:126
本文介绍了未声明“路径"错误.由于其保护级别,它可能无法访问.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会出现此错误-''Path'' is not declared. It may be inaccessible due to its protection level.

我的代码在下面

Why this error is comming - ''Path'' is not declared. It may be inaccessible due to its protection level.

My code is given below

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="uploadfile.aspx.vb" Inherits="uploadfile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
       <p>
            Select File1:<br />
            <input id="File1" type="file"  runat="server" />
            <br />
            Select File2:<br />
            <input id="File2" type="file"  runat="server" />
            <br />
            Select File3:<br />
            <input id="File3" type="file"  runat="server" />
            <br />
            Select File4:<br />
            <input id="File4" type="file"  runat="server" />
        </p>
        <p>
            <asp:Button ID="Button1" runat="server" Text="Upload File" />
 <br />
        </p>
        <span id="Span1"  runat="server">

    </div>
    </form>
</body>
</html>





Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim filepath As String = "C:\Uploads"
        Dim uploadedFiles As HttpFileCollection = Request.Files
        Dim i As Integer = 0

        Do Until i = uploadedFiles.Count
            Dim userPostedFile As HttpPostedFile = uploadedFiles(i)

            Try
                If (userPostedFile.ContentLength > 0) Then
                    Span1.InnerHtml += "File #" & (i + 1) & "<br>"
                    Span1.InnerHtml += "File Content Type: " & userPostedFile.ContentType & "<br>"
                    Span1.InnerHtml += "File Size: " & userPostedFile.ContentLength & "kb<br>"
                    Span1.InnerHtml += "File Name: " & userPostedFile.FileName & "<br>"

                    userPostedFile.SaveAs(filepath & "C:\inetpub\wwwroot" & Path.GetFileName(userPostedFile.FileName))

                    Span1.InnerHtml += "Location where saved: " & filepath & "\" & Path.GetFileName(userPostedFile.FileName) & "<p>"
                End If
            Catch ex As Exception
                Span1.InnerHtml += "Error:<br>" & ex.Message
            End Try
            i += 1
        Loop

    End Sub
</br></p></br></br></br></br>

推荐答案

您有
filepath = "C:\Uploads"


以及您要另存为的文件名


and the name of the file you are trying to save as

filepath & "C:\inetpub\wwwroot" & Path.GetFileName(userPostedFile.FileName)


这意味着您正在尝试使用类似
的名称保存文件


which means that you are trying to save a file with a name like

"C:\UploadsC:\inetpub\wwwrootFileName.Ext"


我不惊讶您收到一条错误消息.


I''m not surprised you are getting an error message.


您的意思是您在第
行有编译错误
You mean you have compilation error on line
userPostedFile.SaveAs(filepath & "C:\inetpub\wwwroot" & Path.GetFileName(userPostedFile.FileName))


?
确保您添加了


?
Make sure you added

using System.IO;


在文件顶部


at the top of the file


这篇关于未声明“路径"错误.由于其保护级别,它可能无法访问.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆